title: Exponential performance drop in macOS with timegm(..) due to timezone lock
body: <p>In my application I experience an exponential slowdown due to a concurrent usage of <code>timegm</code> (at the moment around 800 times slower). I uploaded my test code here: <a href="http://cpp.sh/363nv" rel="nofollow noreferrer">http://cpp.sh/363nv</a></p>
  
  <pre><code>void* testThread(void* args)
  {
      time_t tt;
      tm t;
  
      time(&amp;tt);
      localtime_r(&amp;tt, &amp;t);
  
      for (int i = 0; i &lt; 5000; i++)
      {
          timegm(&amp;t);
      }
  
      return nullptr;
  }
  </code></pre>
  
  <p>The performance drop is caused by a timezone lock. Any idea how to bypass this lock? Depending if I misuse <code>timegm(..)</code> or not, I will file a report to Apple. Thanks for any help</p>
  
  <p>Here are my results:</p>
  
  <p><strong>macOS 10.13.6 (Macbook Pro 2.5 GHz Intel Core i7):</strong></p>
  
  <pre><code>5000 calls of 'timegm' with 1 thread(s) took 0.03634 seconds
  5000 calls of 'timegm' with 8 thread(s) took 24.84911 seconds 
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/7tjRo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7tjRo.png" alt="performance"></a></p>
  
  <p>For a comparison, here are the results of an online c++ execution:</p>
  
  <p><strong>Linux:</strong></p>
  
  <pre><code>5000 calls of 'timegm' with 1 thread(s) took 0.00453 seconds                                                                  
  5000 calls of 'timegm' with 8 thread(s) took 0.00588 seconds 
  </code></pre>