LLVM and TLS
    Jonathan Marler via digitalmars-d-ldc 
    digitalmars-d-ldc at puremagic.com
       
    Tue Feb 17 17:41:56 PST 2015
    
    
  
I've created a simple program to demonstrate the issue.  The 
performance cost of TLS vs __gshared is over one and a half 
orders of magnitude!
import std.stdio;
import std.datetime;
size_t tlsGlobal;
__gshared size_t sharedGlobal;
void main(string[] args)
{
   runTest(3, 10_000_000);
}
void runTest(size_t runCount, size_t loopCount)
{
   writeln("--------------------------------------------------");
   StopWatch sw;
   for(auto runIndex = 0; runIndex < runCount; runIndex++) {
     writefln("run %s (loopcount %s)", runIndex + 1, loopCount);
     sw.reset();
     sw.start();
     for(size_t i = 0; i < loopCount; i++) {
       tlsGlobal = i;
     }
     sw.stop();
     writefln("  TLS   : %s milliseconds", sw.peek.msecs);
     sw.reset();
     sw.start();
     for(size_t i = 0; i < loopCount; i++) {
       sharedGlobal = i;
     }
     sw.stop();
     writefln("  Shared: %s milliseconds", sw.peek.msecs);
   }
}
--------------------------------------------------
Output:
--------------------------------------------------
run 1 (loopcount 10000000)
   TLS   : 104 milliseconds
   Shared: 3 milliseconds
run 2 (loopcount 10000000)
   TLS   : 97 milliseconds
   Shared: 4 milliseconds
run 3 (loopcount 10000000)
   TLS   : 99 milliseconds
   Shared: 3 milliseconds
    
    
More information about the digitalmars-d-ldc
mailing list