Windows multi-threading performance issues on multi-core systems only

Dan dsstruthers at yahoo.com
Tue Dec 15 09:17:45 PST 2009


dsimcha Wrote:

> == Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
> > Maybe I'm wrong, is there a good test case to prove it is worse on
> > multiple cores?
> > -Steve
> 
> This is a synthetic, extreme corner case benchmark, but I think it hammers home
> the point that such problems are at least plausible.  Tested on a Core 2 Quad with
> -O -inline -release:
> 
> import std.stdio, std.perf, core.thread;
> 
> void main() {
>     writeln("Set affinity, then press enter.");
>     readln();
> 
>     auto pc = new PerformanceCounter;
>     pc.start;
> 
>     enum nThreads = 4;
>     auto threads = new Thread[nThreads];
>     foreach(ref thread; threads) {
>         thread = new Thread(&doAppending);
>         thread.start();
>     }
> 
>     foreach(thread; threads) {
>         thread.join();
>     }
> 
>     pc.stop;
>     writeln(pc.milliseconds);
> }
> 
> void doAppending() {
>     uint[] arr;
>     foreach(i; 0..1_000_000) {
>         arr ~= i;
>     }
> }
> 
> Timing with affinity for all 4 CPUs:  28390 milliseconds
> 
> Timing with affinity for only 1 CPU:  533 milliseconds

My code does do considerable array appending, and I see exactly the same issue as dsimcha points out above.  I would expect it is GC related, but why for multiple cores only, I cannot fathom.

Thanks for the repro, dsimcha!  My code snippet would not have been as straight-forward.



More information about the Digitalmars-d mailing list