[erlang-questions] unpacking big/little endian speed difference

Kostis Sagonas <>
Tue Oct 13 16:31:05 CEST 2015


On 10/13/2015 02:59 PM, Sergej Jurečko wrote:
> How come unpacking integers as big endian is faster than little endian,
> when I'm running on a little endian platform (intel osx)?
> I know big endian is erlang default, but if you're turning binaries into
> integers, you must turn them into little endian anyway, so unpacking
> should basically be memmcpy.
>
> The test:
>
> % Takes:  ~1.3s
> -define(ENDIAN,unsigned-big).
>
> % Takes: ~1.8s
> % -define(ENDIAN,unsigned-little).

Well, if you are interested in performance, simply compile to native 
code your module and the time will drop to less than half...

================================================================
Eshell V7.1  (abort with ^G)
1> c(endian).
{ok,endian}
2> endian:loop().
1097971
3> endian:loop().
1327621
4> endian:loop().
1162506
5> endian:loop().
1103813
6> c(endian, [native]).
{ok,endian}
7> endian:loop().
414000
8> endian:loop().
441327
================================================================

Kostis


More information about the erlang-questions mailing list