<html dir="ltr"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body style="text-align:left; direction:ltr;"><div>Hi Oliver,</div><div><br></div><div>I've tried to reproduce this discrepancy on my machine, but I can only see a modest difference on latest OTP 21 (the results are in microseconds):</div><div><br></div><pre>Erlang/OTP 21 [erts-10.3.1] [source] [64-bit] [smp:24:24] [ds:24:24:10] [async-threads:1] [hipe]</pre><pre><br></pre><pre>Eshell V10.3.1  (abort with ^G)</pre><pre>1> c(t, []).           </pre><pre>{ok,t}</pre><pre>2> t:bench(one).       </pre><pre>15957304</pre><pre>3> t:bench(union).</pre><pre>559470</pre><pre>4> c(t, [native]).     </pre><pre>{ok,t}</pre><pre>5> t:bench(one).  </pre><pre>3611371</pre><pre>6> t:bench(union).</pre><pre>501871</pre><div><br></div><div>I've attached the source code I used for this test, am I missing something?</div><div><br></div><div>Regards,</div><div>John Högberg</div><div><br></div><div>On Wed, 2019-03-27 at 10:09 +0100, Oliver Bollmann wrote:</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex">
    <p>I use, with binaries like <<1:1000000>>,</p>
    <pre>one(<span style="color:#660e7a;">F</span>,<<<span style="color:#660e7a;">Size</span>:<span style="color:#0000ff;">64</span>/unsigned, <span style="color:#660e7a;">Bitmap</span>:<span style="color:#660e7a;">Size</span>/bitstring, <span style="color:#660e7a;">_</span>/bitstring>><span style="color:#660e7a;"></span>) -></pre><pre>  one(<span style="color:#660e7a;">F</span>,<span style="color:#660e7a;">Bitmap</span>,<span style="color:#0000ff;">0</span>,[])<span style="color:#000080;font-weight:bold;">.</span></pre><pre>one(<span style="color:#660e7a;">F</span>, <<<span style="color:#0000ff;">0</span>:<span style="color:#0000ff;">1</span>, <span style="color:#660e7a;">R</span>/bitstring>>, <span style="color:#660e7a;">N</span>, <span style="color:#660e7a;">Acc</span>) -></pre><pre>  one(<span style="color:#660e7a;">F</span>, <span style="color:#660e7a;">R</span>, <span style="color:#660e7a;">N </span>+ <span style="color:#0000ff;">1</span>, <span style="color:#660e7a;">Acc</span>);</pre><pre>one(<span style="color:#660e7a;">F</span>, <<<span style="color:#0000ff;">1</span>:<span style="color:#0000ff;">1</span>, <span style="color:#660e7a;">R</span>/bitstring>>, <span style="color:#660e7a;">N</span>, <span style="color:#660e7a;">Acc</span>) -></pre><pre>  one(<span style="color:#660e7a;">F</span>, <span style="color:#660e7a;">R</span>, <span style="color:#660e7a;">N </span>+ <span style="color:#0000ff;">1</span>, [<span style="color:#660e7a;">F</span>(<span style="color:#660e7a;">N</span>) | <span style="color:#660e7a;">Acc</span>]);</pre><pre>one(<span style="color:#660e7a;">_</span>, <<>>, <span style="color:#660e7a;">_</span>, <span style="color:#660e7a;">Acc</span>) -> <span style="color:#660e7a;">Acc</span><span style="color:#000080;font-weight:bold;">.</span></pre><pre><span style="color:#000080;font-weight:bold;"></span></pre><pre>union(<<<span style="color:#660e7a;">Size</span>:<span style="color:#0000ff;">64</span>/unsigned, <span style="color:#660e7a;">L</span>:<span style="color:#660e7a;">Size</span>/unsigned, <span style="color:#660e7a;">P</span>/bitstring>>,</pre><pre>    <<<span style="color:#660e7a;">Size</span>:<span style="color:#0000ff;">64</span>/unsigned, <span style="color:#660e7a;">R</span>:<span style="color:#660e7a;">Size</span>/unsigned, <span style="color:#660e7a;">_</span>/bitstring>>) -></pre><pre>  <<<span style="color:#660e7a;">Size</span>:<span style="color:#0000ff;">64</span>/unsigned, (<span style="color:#660e7a;">L </span><span style="color:#000080;font-weight:bold;">bor </span><span style="color:#660e7a;">R</span>):<span style="color:#660e7a;">Size</span>/unsigned, <span style="color:#660e7a;">P</span>/bitstring>><span style="color:#000080;font-weight:bold;">.</span></pre><pre><br></pre>
    <p>and call this functions 1,000,000 times, this takes for 1,000
      calls about 20 minutes, <br>
    </p>
    <p>if i compile with native -compile([native,{hipe, o2}])<span style="color:#000080;font-weight:bold;"> </span>it takes 3
      seconds for 1,000 calls, so it is about 400x faster !!</p>
    <p>OS: OSX<br>
    </p>
    <p>What is the secret?<span style="color:#000080;font-weight:bold;"></span></p>
    <pre>-- </pre><pre>Grüße</pre><pre>Oliver Bollmann</pre>
  

<pre>_______________________________________________</pre><pre>erlang-questions mailing list</pre><pre><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a></pre><pre><a href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a></pre><pre><br></pre></blockquote></body></html>