surprising result with hipe compilation
Ulf Wiger (AL/EAB)
ulf.wiger@REDACTED
Thu Oct 30 17:06:31 CET 2003
From: Mikael Pettersson [mailto:mikpe@REDACTED]
>To summarise: You compile to native code and save it in files,
>and then benchmark it with timer:tc as the first thing you
>do in a fresh system. This gives much worse results (longer
>time taken) than if the code was only in BEAM.
Yes, obviously, but this is not what I did.
I called timer:tc(...) several times and picked the fastest
one.
>If one repeats the timer:tc call, the runtime for both BEAM and
>native code is reduced to normal levels, and native code is
>consistently (for your code) faster than BEAM.
This is not what happens on my machine (a 400 MHz Ultra 10):
[etxuwig@REDACTED]: erlc +native *.erl
[etxuwig@REDACTED]: which erl
/OTP/LXA_11930_R9C_3/bin/erl
[etxuwig@REDACTED]: erl -boot start_clean -pa .
Erlang (BEAM) emulator version 5.3 [hipe] [threads:0]
Eshell V5.3 (abort with ^G)
1> timer:tc(test,run,[]).
{334894,
{ok,[{name,"file_server"},
{vsn,"ubf1.0"},
{types,[{info,{constant,info},[]},
{description,{constant,description},[]},
{services,{constant,services},[]},
{contract,{constant,contract},[]},
{file,{prim,string},[]},
{ls,{constant,ls},[]},
{files,{tuple,[{constant,files},{list,{prim,file}}]},[]},
{getFile,{tuple,[{constant,get},{prim,file}]},[]},
{noSuchFile,{constant,noSuchFile},[]}]},
{transition,{start,[{input,{prim,ls},[{output,{prim,files},start}]},
{input,{prim,getFile},
[{output,{prim,binary},start},
{output,{prim,noSuchFile},stop}]}]}},
{anystate,[{{prim,info},{prim,string}},
{{prim,description},{prim,string}},
{{prim,contract},{prim,term}}]}]}}
2> element(1,timer:tc(test,run,[])).
10511
3> element(1,timer:tc(test,run,[])).
27083
4> element(1,timer:tc(test,run,[])).
11149
5> element(1,timer:tc(test,run,[])).
10846
6> element(1,timer:tc(test,run,[])).
11326
7> element(1,timer:tc(test,run,[])).
10887
8> element(1,timer:tc(test,run,[])).
10573
9>
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution
a
[etxuwig@REDACTED]: erlc -W *.erl
[etxuwig@REDACTED]: erl -boot start_clean -pa .
Erlang (BEAM) emulator version 5.3 [hipe] [threads:0]
Eshell V5.3 (abort with ^G)
1> timer:tc(test,run,[]).
{36540,
{ok,[{name,"file_server"},
{vsn,"ubf1.0"},
{types,[{info,{constant,info},[]},
{description,{constant,description},[]},
{services,{constant,services},[]},
{contract,{constant,contract},[]},
{file,{prim,string},[]},
{ls,{constant,ls},[]},
{files,{tuple,[{constant,files},{list,{prim,file}}]},[]},
{getFile,{tuple,[{constant,get},{prim,file}]},[]},
{noSuchFile,{constant,noSuchFile},[]}]},
{transition,{start,[{input,{prim,ls},[{output,{prim,files},start}]},
{input,{prim,getFile},
[{output,{prim,binary},start},
{output,{prim,noSuchFile},stop}]}]}},
{anystate,[{{prim,info},{prim,string}},
{{prim,description},{prim,string}},
{{prim,contract},{prim,term}}]}]}}
2> element(1,timer:tc(test,run,[])).
6054
3> element(1,timer:tc(test,run,[])).
6451
4> element(1,timer:tc(test,run,[])).
5938
5> element(1,timer:tc(test,run,[])).
6226
6> element(1,timer:tc(test,run,[])).
6407
7>
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution
a
When compiled with hipe, the code runs significantly slower.
Dynamic loading of modules is indeed much (10x) slower when
compiled to native code.
I tried running a call trace to find out which other modules
were used in the test. It was just prim_file.erl and io_lib.erl,
but compiling those two as well (esp. prim_file.erl) made
the test run slightly slower still when compiled with hipe.
/Uffe
More information about the erlang-questions
mailing list