I've created a task to execute in C#. I tried to watch the execution time and i noticed something strange (at least for me). The task is this :
static void Main(string[] args)
{
jump: // Task is starting
Gameboard board = new Gameboard(); //initialize things
board.Initialize_NewGame(); //initialize things
ChessEngine engine = new ChessEngine(); //initialize things
Stopwatch watch = new Stopwatch(); //initialize things
watch.Start(); // *** Stopwatch Starts ***
foreach (Piece piece in board.Pieces)
{
if (piece.Color == 'W') engine.Generate_Moves(piece, new VitrualGameboard(board.Squares, board.Pieces));
}
watch.Stop(); // *** Stopwatch Starts ***
Console.WriteLine("Moves generated in :" + watch.Elapsed.TotalMilliseconds.ToString("0.00") + " ms total");
if (Console.ReadLine() == "") goto jump;
}
So after the watch.Stop() i can print the execution time and IF i press Enter the task starts again and i get more results in milliseconds always.
Now let me show you the results on the image.

So how is this possible? I mean the difference in the first execution is obvious.
Does CPU cache memory has something to do with this ?

New Topic/Question
Reply



MultiQuote



|