Created
September 17, 2017 13:01
-
-
Save ggcampinho/d1976bafb0b4afa406784c93f15ad547 to your computer and use it in GitHub Desktop.
Benchmark with implementation
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
List = fun () -> | |
L = lists:seq(1, 1000), | |
lists:map(fun(_) -> ok end, L) ++ lists:map(fun(_) -> {error, "error"} end, L) | |
end. | |
Withcase = fun(X) -> | |
case X of | |
ok -> | |
case X of | |
ok -> ok; | |
{error, Msg} when is_atom(Msg) -> error; | |
{error, _Msg} -> error | |
end; | |
{error, Msg} when is_atom(Msg) -> error; | |
{error, _Msg} -> error | |
end | |
end. | |
Withtry = fun(X) -> | |
try | |
ok = X, | |
ok = X | |
of | |
_ -> ok | |
catch | |
error:{badmatch,Y} -> | |
case Y of | |
{error, Msg} when is_atom(Msg) -> error; | |
{error, _Msg} -> error | |
end | |
end | |
end. | |
benchee:run( | |
#{ | |
test_with_case => | |
fun () -> lists:map(Withcase, List()) end, | |
test_with_try => | |
fun () -> lists:map(Withtry, List()) end | |
}, | |
[{warmup, 0}, {time, 2}] | |
). |
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
Operating System: macOS | |
CPU Information: Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz | |
Number of Available Cores: 4 | |
Available memory: 17.179869184 GB | |
Elixir 1.5.1 | |
Erlang 20.0 | |
Benchmark suite executing with the following configuration: | |
warmup: 0.0 μs | |
time: 2.00 s | |
parallel: 1 | |
inputs: none specified | |
Estimated total run time: 4.00 s | |
Benchmarking test_with_case... | |
Benchmarking test_with_try... | |
Name ips average deviation median | |
test_with_try 116.06 8.62 ms ±10.57% 8.14 ms | |
test_with_case 91.66 10.91 ms ±10.28% 10.32 ms | |
Comparison: | |
test_with_try 116.06 | |
test_with_case 91.66 - 1.27x slower | |
#{'__struct__' => 'Elixir.Benchee.Suite', | |
configuration => | |
#{'__struct__' => 'Elixir.Benchee.Configuration', | |
assigns => #{}, | |
formatter_options => | |
#{console => #{comparison => true,unit_scaling => best}}, | |
formatters => | |
[#Fun<Elixir.Benchee.Formatters.Console.output.1>], | |
inputs => nil,parallel => 1, | |
print => | |
#{benchmarking => true,configuration => true, | |
fast_warning => true}, | |
time => 2000000,warmup => 0}, | |
jobs => | |
#{<<"test_with_case">> => #Fun<erl_eval.20.99386804>, | |
<<"test_with_try">> => #Fun<erl_eval.20.99386804>}, | |
run_times => | |
#{'__no_input' => | |
#{<<"test_with_case">> => | |
[10451,10443,10902,14726,13647,13038,10446,10144,12519, | |
10690,12103,10328,10104,10281,12972,10309,12332,11037,10105, | |
12652,10602,10559,12746|...], | |
<<"test_with_try">> => | |
[8529,7965,7959,9227,8534,12104,11434,8674,10536,8971,7987, | |
8371,8258,8058,7963,7938,8002,9510,8639,7985,8013,8380|...]}}, | |
statistics => | |
#{'__no_input' => | |
#{<<"test_with_case">> => | |
#{'__struct__' => 'Elixir.Benchee.Statistics', | |
average => 10909.46195652174,ips => 91.6635489436025, | |
maximum => 15006,median => 10316.0,minimum => 9943, | |
sample_size => 184,std_dev => 1121.9193272306004, | |
std_dev_ips => 9.42659753269481, | |
std_dev_ratio => 0.10283910716237572}, | |
<<"test_with_try">> => | |
#{'__struct__' => 'Elixir.Benchee.Statistics', | |
average => 8616.0,ips => 116.0631383472609,maximum => 12104, | |
median => 8140.0,minimum => 7775,sample_size => 233, | |
std_dev => 911.0921522388636, | |
std_dev_ips => 12.273005398375455, | |
std_dev_ratio => 0.10574421451240293}}}, | |
system => | |
#{available_memory => <<"17.179869184 GB">>, | |
cpu_speed => <<"Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz">>, | |
elixir => <<"1.5.1">>,erlang => <<"20.0">>,num_cores => 4, | |
os => macOS}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment