[erlang-questions] how to do faster integer operations (was: some language changes)

Paul Mineiro <>
Thu Jun 7 08:36:28 CEST 2007


I setup IA32 and IA64 chroots on the same box, and ran the benchmark.
I get almost a 20x improvement (!).  Unfortunately the erlang version is
slightly different (testing vs. sarge), but nonethless I'm assuming this
is due to boxing differences.

On my original problem (which I cannot post for IP reasons), I get about
a 10x improvement putting the performance about 2x worse than Haskell using
Word32 and about 10x worse than native C, but still far better than 100x
worse than native C.

It's been a good lesson to discover that using less than the full machine
width for integers leads to significant speed up.  Is there a FAQ for
performance where this kind of knowledge is accumulated?

Thanks everybody for the assistance,

-- p

[ This machine is faster than the previous one I was using, btw, which
is why the original benchmark is about 2.5x faster than what I reported
originally. ]

% erl                                                  ~/tmp
Erlang (BEAM) emulator version 5.5.2 [source] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.5.2  (abort with ^G)
1> c (megahash, [ native, o2 ]).
{ok,megahash}
2> megahash:benchmark ().
361384

% erl                                                   ~/tmp
Erlang (BEAM) emulator version 5.5.4 [source] [64-bit] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.5.4  (abort with ^G)
1> c (megahash, [ native, o2 ]).
{ok,megahash}
2> megahash:benchmark ().
15095
3>


On Wed, 6 Jun 2007, Roger Larsson wrote:

> On Wednesday 06 June 2007 11:27, Paul Mineiro wrote:
> > paraphrasing ok <>:
> >
> > [ a machine width integer type won't help in Erlang because it's
> > dynamically typed ... maybe there's another way to speed this up ...
> >  share the function and we'll see ]
> >
> > Alright, well, I've isolated a "sufficiently generic" part of the
> > computation which is still disappointingly slow (attached).  My
> > machine can do 100K in circa 1s using hipe compilation; the equivalent
> > C is about 2 orders of magnitude faster.
> >
>
> > erl
> Erlang (BEAM) emulator version 5.5.4 [source] [64-bit] [async-threads:0]
> [hipe] [kernel-poll:false]
>
> Eshell V5.5.4  (abort with ^G)
> 1> c(megahash).
> {ok,megahash}
> 2> megahash:benchmark().
> 236086
> 3> megahash:benchmark().
> 235660
>
> Mine does a lot better (but I have no idea on how fast your CPU is),
> notice that I run 64-bit AMD.
>
>   D0 = 16#9e3779b9,
> I think this code can be a problem the problem might be related to your use
> of 32 bit integers - they will not fit since the Erlang uses a tag for dynamic
> type handling. With 64-bit processor both the tag and the 32-bits value fit
> in one 64-bit register.
>
> > cat /proc/cpuinfo
> processor       : 0
> vendor_id       : AuthenticAMD
> cpu family      : 15
> model           : 47
> model name      : AMD Athlon(tm) 64 Processor 3500+
> stepping        : 0
> cpu MHz         : 1000.000
> cache size      : 512 KB
> fpu             : yes
> fpu_exception   : yes
> cpuid level     : 1
> wp              : yes
> flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
> cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt lm
> 3dnowext 3dnow up pni lahf_lm
> bogomips        : 2001.39
> TLB size        : 1024 4K pages
> clflush size    : 64
> cache_alignment : 64
> address sizes   : 40 bits physical, 48 bits virtual
> power management: ts fid vid ttp tm stc
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>

Programmers crave flexibility. Whether they sacrifice a little flexibility
in order to enforce valuable principles depends on their experience and
philosophy derived from that experience. If they have learned the hard
way that sometimes even geniuses make mistakes or do the expedient thing,
they will fight to make mechanisms work correctly by design.

        -- Terence Parr



More information about the erlang-questions mailing list