<div dir="ltr">The difference is really in "i_bs_get_integer_32_rfId" and "i_bs_get_integer_small_imm_xIfId".<div><br></div><div>When looking in code, the "i_bs_get_integer_32_rfId" can extract 32 bit big endian integer from bitstring - it is quite simple function, which can not do much more, and even has fast path for binary (bitstring with byte boundary).</div><div>On the other side "i_bs_get_integer_small_imm_xIfId" is quite complex function, which can extract integer with any bit size, signed, or unsigned, little, or big endian. It is quite complex, and even use some temporary allocated buffers.</div><div><br></div><div>So the reason is, that there is special "fast" opcode for extracting 32 bit big endian integer (probably because authors of BEAM VM thought, that it will be more useful).</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 13, 2015 at 4:31 PM, Kostis Sagonas <span dir="ltr"><<a href="mailto:kostis@cs.ntua.gr" target="_blank">kostis@cs.ntua.gr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 10/13/2015 02:59 PM, Sergej Jurečko wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
How come unpacking integers as big endian is faster than little endian,<br>
when I'm running on a little endian platform (intel osx)?<br>
I know big endian is erlang default, but if you're turning binaries into<br>
integers, you must turn them into little endian anyway, so unpacking<br>
should basically be memmcpy.<br>
<br>
The test:<br>
<br>
% Takes:  ~1.3s<br>
-define(ENDIAN,unsigned-big).<br>
<br>
% Takes: ~1.8s<br>
% -define(ENDIAN,unsigned-little).<br>
</blockquote>
<br></span>
Well, if you are interested in performance, simply compile to native code your module and the time will drop to less than half...<br>
<br>
================================================================<br>
Eshell V7.1  (abort with ^G)<br>
1> c(endian).<br>
{ok,endian}<br>
2> endian:loop().<br>
1097971<br>
3> endian:loop().<br>
1327621<br>
4> endian:loop().<br>
1162506<br>
5> endian:loop().<br>
1103813<br>
6> c(endian, [native]).<br>
{ok,endian}<br>
7> endian:loop().<br>
414000<br>
8> endian:loop().<br>
441327<br>
================================================================<span class="HOEnZb"><font color="#888888"><br>
<br>
Kostis</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div>