Created
July 21, 2013 17:22
-
-
Save yfyf/6049220 to your computer and use it in GitHub Desktop.
testing performance of reflection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(refl). | |
-compile(export_all). | |
normal(Foo) -> | |
lists:sort([Foo]). | |
bad(Mod, Fun, Foo) -> | |
Mod:Fun([Foo]). | |
bench(NumTests) -> | |
Seq = lists:seq(1, NumTests), | |
{FastTime, _} = timer:tc(fun lists:foreach/2, | |
[fun (_) -> normal(foo) end, Seq]), | |
timer:sleep(1000), | |
{SlowTime, _} = timer:tc(fun lists:foreach/2, | |
[fun (_) -> bad(lists, sort, foo) end, Seq]), | |
io:format("ResultFast: ~pms~n", [FastTime/1000]), | |
io:format("ResultSlow: ~pms~n", [SlowTime/1000]). | |
----------------- | |
Eshell V5.9.3 (abort with ^G) | |
1> refl:bench(1000). | |
ResultFast: 0.147ms | |
ResultSlow: 0.239ms | |
ok | |
2> refl:bench(1000*1000). | |
ResultFast: 42.222ms | |
ResultSlow: 73.34ms | |
ok | |
3> refl:bench(100*1000*1000). | |
ResultFast: 4661.811ms | |
ResultSlow: 6813.099ms | |
ok |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment