caching - C# - Why does the first iteration of this loop run slower than the rest? -


i'm doing bit of benchmarking test something. i've got large array of 100 million 64 bit ints, randomly choose 10 million of , few operations. indexes randomly chosen because i'm trying keep cpu caching as can, while still getting accurate benchmark. first iteration of loop takes .3 seconds, of others taking .2 seconds. guess parts of cone[] still in cache, think array of size wouldn't able store much. other thoughts?

perhaps jit issue?

static void main(string[] args)     {          int64[] cone = new int64[100000001];          (int m = 0; m < 20; ++m)         {             int[] num2 = new int[10000001];             random rand = new random();              (int = 0; < 10000000; ++i)             {                 num2[i] = rand.next(100000000);             }              datetime start = datetime.now;              (int = 0; < 10000000; ++i)             {                 cone[num2[i]] = i;                 if (cone[i] > 0) ++cone[i];              }              datetime finish = datetime.now;             timespan elapsed = finish - start;              console.writeline("took: {0}", elapsed);             thread.sleep(100);         }         console.readline();     } 

may code jitted first time hit loop. compile time what's making slow? ran c++ version of code , seems have same latency every iteration.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -