Group Abstract Group Abstract

Message Boards Message Boards

3
|
12.1K Views
|
13 Replies
|
10 Total Likes
View groups...
Share
Share this post:

Benchmarking: unexplained switching between high and low performance

Posted 9 years ago
POSTED BY: Szabolcs Horvát
13 Replies
Posted 9 years ago
POSTED BY: David Keith

The forum has a notoriously droll sense of humor.

POSTED BY: Daniel Lichtblau

This has happened to me before. I tried to make a new post, and instead it duplicated the previous one.

POSTED BY: Szabolcs Horvát

Hi Szabolcs, I have no solution but I did find some consistent behaviour on my system.(win10 mm11.1). I timed just the same a+b a lot of times and the first run is not always faster than the subsequent runs. For small arrays the first run is slower and for larger it is faster. On my computer it seems to "switch" at an array size of 130564. I ran it multiple times and it seems "consistent". Perhaps this helps in the troubleshooting process.

g[seed_, array_] :=
 Block[{out = 
    Table[SeedRandom[seed]; a = RandomReal[1, array]; 
     b = RandomReal[1, array]; 
     Reap[For[i = 0, i < 200, i++, Sow[AbsoluteTiming[(a + b);]]]][[2,
        1, All, 1]], {30}]}, Map[Mean, out\[Transpose]]]
list = Table[
  Block[{data = g[12567, 130530 + x]}, 
   Show[ListPlot[data, PlotRange -> {{0, 200}, {0, 0.0005}}, 
     AxesOrigin -> {0, 0}, AspectRatio -> Full, 
     PlotLabel -> 130540 + x], 
    Graphics[{PointSize[Large], Red, Point[{1, data[[1]]}]}]]], {x, 0,
    35}]

The run time also rises at that point. enter image description here

POSTED BY: l van Veen
POSTED BY: Szabolcs Horvát
  • First thought: RepeatedTiming uses a trimmed mean, such that outliers (either fast or slow) are removed, such that catching outliers might be even harder...
  • Second thought: 2 million floats (16MB?) will be generally be larger than the CPU cache which is generally, 4, 6 of 8 MB for desktop/laptop machines. Could that influence it? If it needs just 2 full caches, or if other processes have remnants, it needs 3 caches? just a thought, not an export on this...
POSTED BY: Sander Huisman

I slightly changed your code:

timings=Table[
    n=1000000+8000 j;
    SeedRandom[120];
    a=RandomReal[1,n];
    b=RandomReal[1,n];
    First@AbsoluteTiming[Do[a+b;,{5}]]
,
    {10}
,
    {j,20}
]
ListPlot[Flatten[timings],PlotRange->{0,All}]

giving:

enter image description here

very reproducible behavior... Not yet sure what the cause is though...

POSTED BY: Sander Huisman

Thanks! This change to the code is useful. The only problem is that I do not trust very short timings. As I remember, on Windows XP, the timer's resolution was more than 10 ms. This shouldn't be an issue on today's OSs, but short timings are still much more affected by fluctuations. Here's the same with more repetitions in the Do. The result is basically the same what you showed:

timings = Table[n = 1000000 + 8000 j;
  SeedRandom[120];
  a = RandomReal[1, n];
  b = RandomReal[1, n];
  First@AbsoluteTiming[Do[a + b;, {500}]], {10}, {j, 20}]
ListPlot[Flatten[timings], PlotRange -> {0, All}]

With Turbo Boost on:

enter image description here

With Turbo Boost off:

enter image description here

It is strange that in addition to the slow-fast pattern, each subsequent evaluation gets slower than the previous one.

POSTED BY: Szabolcs Horvát

That's because of the 1000000+ 8000*j right? the calculation becomes slightly bigger each time?

POSTED BY: Sander Huisman
Posted 9 years ago

Running Sanders code:

In[8]:= $Version

Out[8]= "11.1.0 for Microsoft Windows (64-bit) (March 13, 2017)"

enter image description here

enter image description here

POSTED BY: David Keith

Your Xeon CPU probably has more cache, could you try:

n=1000000+20000 j;

?

POSTED BY: Sander Huisman
Posted 9 years ago

With n=1000000+20000 j;

enter image description here

Why would more cache always give me the slow timings? Or are these all fast timings on a slower system?

POSTED BY: David Keith

Hi I got these results. Not much difference because they are all slow (although 0.0046 is slowest) compared to your beast machine ;) Win10 MM11.1

{{{20000,{0.0035,0.0037,0.0035,0.0036,0.0037}}, {40000,{0.0036,0.0034,0.0036,0.0035,0.0039}}, {60000,{0.0041,0.0040,0.0039,0.0036,0.0037}}, {80000,{0.0036,0.0037,0.0037,0.0036,0.0038}}, {100000,{0.00362,0.0038,0.0037,0.0042,0.0045}}, {120000,{0.0040,0.0038,0.0038,0.0045,0.0038}}, {140000,{0.0038,0.0038,0.0044,0.0038,0.0038}}, {160000,{0.0039,0.0038,0.0041,0.0039,0.0041}}, {180000,{0.0042,0.0040,0.0040,0.0040,0.0039}}, {200000,{0.0042,0.0040,0.0040,0.0043,0.0041}}},

{{20000,{0.0034,0.0035,0.0034,0.0034,0.0035}}, {40000,{0.0036,0.0036,0.0035,0.0035,0.0041}}, {60000,{0.0040,0.0037,0.0037,0.0036,0.0037}}, {80000,{0.0037,0.0037,0.0037,0.0037,0.0037}}, {100000,{0.0039,0.0038,0.0038,0.0037,0.0044}}, {120000,{0.0046,0.0046,0.0038,0.0038,0.0037}}, {140000,{0.0040,0.0039,0.0038,0.0042,0.0040}}, {160000,{0.0039,0.0039,0.0038,0.0039,0.0039}}, {180000,{0.0040,0.0040,0.0040,0.0040,0.0040}}, {200000,{0.0041,0.0041,0.0040,0.0043,0.0041}}}}

POSTED BY: l van Veen
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard