[erlang-questions] Benchmark on arg matching
datacompboy
datacompboy@REDACTED
Sat Sep 30 12:35:10 CEST 2006
For soap-message router, I have lot of
soap(R) when is_record(R,'p:Req1') ->
req1(R);
code
"Interest, will be faster, if I write soap(#'p:Req1'{} = R) -> req1(R) ?", so I get benchmark from efficiency_guide, and eval following tests:
For benchmarking of only simple call rounter:
foo(_T) -> ok.
foo_unboundrec_l(#test{}=T) -> foo(T),ok;
foo_unboundrec_l(_) -> io:format("error!").
foo_unboundrec_r(T=#test{}) -> foo(T),ok;
foo_unboundrec_r(_) -> io:format("error!").
foo_parboundrec_l(#test{f1=_F1,f3=_F3}=T) -> foo(T),ok;
foo_parboundrec_l(_) -> io:format("error!").
foo_parboundrec_r(T=#test{f1=_F1,f3=_F3}) -> foo(T),ok;
foo_parboundrec_r(_) -> io:format("error!").
foo_allboundrec_l(#test{f1=_F1,f2=_F2,f3=_F3,f4=_F4}=T) -> foo(T),ok;
foo_allboundrec_l(_) -> io:format("error!").
foo_allboundrec_r(T=#test{f1=_F1,f2=_F2,f3=_F3,f4=_F4}) -> foo(T),ok;
foo_allboundrec_r(_) -> io:format("error!").
foo_allboundrec(#test{f1=F1,f2=F2,f3=F3,f4=F4}) -> foo(#test{f1=F1,f2=F2,f3=F3,f4=F4}),ok;
foo_allboundrec(_) -> io:format("error!").
foo_whenisrec(T) when is_record(T, test) -> foo(T),ok;
foo_whenisrec(_) -> io:format("error!").
Here is results:
Test
allboundrec_r 1.00
unboundrec_l 1.00
parboundrec_l 1.02
allboundrec_l 1.02
whenisrec 1.02
unboundrec_r 1.06
parboundrec_r 1.06
allboundrec 1.83
-- no difference, except of its expensive to build record from scratch.
But if you needed in part of record here, in router:
foo_unboundrec_l(#test{}=T) -> foo(T),T#test.f1,T#test.f3,ok;
foo_unboundrec_l(_) -> io:format("error!").
foo_unboundrec_r(T=#test{}) -> foo(T),T#test.f1,T#test.f3,ok;
foo_unboundrec_r(_) -> io:format("error!").
foo_parboundrec_l(#test{f1=F1,f3=F3}=T) -> foo(T),F1,F3,ok;
foo_parboundrec_l(_) -> io:format("error!").
foo_parboundrec_r(T=#test{f1=F1,f3=F3}) -> foo(T),F1,F3,ok;
foo_parboundrec_r(_) -> io:format("error!").
foo_allboundrec_l(#test{f1=F1,f2=_F2,f3=F3,f4=_F4}=T) -> foo(T),F1,F3,ok;
foo_allboundrec_l(_) -> io:format("error!").
foo_allboundrec_r(T=#test{f1=F1,f2=_F2,f3=F3,f4=_F4}) -> foo(T),F1,F3,ok;
foo_allboundrec_r(_) -> io:format("error!").
foo_allboundrec(#test{f1=F1,f2=F2,f3=F3,f4=F4}) -> foo(#test{f1=F1,f2=F2,f3=F3,f4=F4}),F1,F3,ok;
foo_allboundrec(_) -> io:format("error!").
foo_whenisrec(T) when is_record(T, test) -> foo(T),T#test.f1,T#test.f3,ok;
foo_whenisrec(_) -> io:format("error!").
foo_whenisrec_ml(T) when is_record(T, test) -> #test{f1=F1,f3=F3}=T,foo(T),F1,F3,ok;
foo_whenisrec_ml(_) -> io:format("error!").
I'm got such result:
parboundrec_l 1.00
allboundrec_r 1.00
allboundrec_l 1.02
unboundrec_l 1.25
whenisrec_ml 1.25
unboundrec_r 1.25
whenisrec 1.37
parboundrec_r 1.58
allboundrec 2.00
So, if you needed in part of result, better to match in header, than use "when is_record()".
--
--- suicide proc near\n call death\n suicide endp
_________________________________________________________
Post sent from http://www.trapexit.org
More information about the erlang-questions
mailing list