surprising result with hipe compilation
Ulf Wiger (AL/EAB)
ulf.wiger@REDACTED
Tue Oct 21 11:47:17 CEST 2003
I experimented a bit with a recursive-descent parser, and thought
I'd check whether compiling to native code could speed things up:
First, clocking the parse operation without hipe compilation:
41> timer:tc(contract_parser1,read_and_parse,["file_plugin.con"]).
{5860,
{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}}]}]}}
This was ~2ms slower than the yecc-generated parse module.
(To be expected. It's supposed to be slower.)
Now, compiling the parse module with hipe:
42> c(contract,[native]).
{module,contract}
...
45> timer:tc(contract_parser1,read_and_parse,["file_plugin.con"]).
{16958,
{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}}]}]}}
Oops! Slight slow-down. Perhaps all those transitions between threaded
and native...? Hipe-compile the module calling the parser:
52> c(contract_parser1,[native]).
{ok,contract_parser1}
53> timer:tc(contract_parser1,read_and_parse,["file_plugin.con"]).
{75,
{'EXIT',{undef,[{contract_parser1,read_and_parse,["file_plugin.con"]},
{timer,tc,3},
{erl_eval,expr,3},
{erl_eval,exprs,4},
{shell,eval_loop,2}]}}}
Oops again! This looks like a bug, or am I missing something?
The source is available upon request.
/Uffe
More information about the erlang-questions
mailing list