Last active
July 15, 2016 14:45
-
-
Save lpgauth/b54cb113700fc1dfa29fb4111b94827b to your computer and use it in GitHub Desktop.
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(flare_timing). | |
-export([ | |
bench/0 | |
]). | |
%% public | |
bench() -> | |
bench("random_1", fun () -> random_1(1000000) end, 1000000, 50), | |
bench("random_2", fun () -> random_2(1000000) end, 1000000, 50), | |
bench("random_3", fun () -> random_3(1000000) end, 1000000, 50), | |
bench("server_name_1", fun () -> server_name_1(<<"test">>, 1) end, 1000000, 50), | |
bench("server_name_2", fun () -> server_name_2(<<"test">>, 1) end, 1000000, 50). | |
%% private | |
bench(Name, Fun, N, P) -> | |
R = timing:function(Fun, N, P), | |
{_, Value} = lists:keyfind(arithmetic_mean, 1, R), | |
{_, Value2} = lists:keyfind(percentile, 1, R), | |
io:format("~s: mean ~p~n", [Name, Value]), | |
io:format("~s percentile ~p~n", [Name, Value2]). | |
random_1(N) -> | |
rand:uniform(N). | |
random_2(N) -> | |
erlang:phash2({self(), os:timestamp()}, N) + 1. | |
random_3(N) -> | |
granderl:uniform(N). | |
server_name_1(Topic, Index) -> | |
list_to_atom("flare_topic_" ++ binary_to_list(Topic) ++ | |
"_" ++ integer_to_list(Index)). | |
server_name_2(<<"test">>, 1) -> | |
flare_topic_test_1. |
Author
lpgauth
commented
Jul 15, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment