Skip to content

Commit

Permalink
benchmarking!
Browse files Browse the repository at this point in the history
  • Loading branch information
deadtrickster committed Oct 2, 2016
1 parent 20fb4c1 commit ee0ba47
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
66 changes: 38 additions & 28 deletions benchmark.erl → benchmark/benchmark_counter.erl
@@ -1,20 +1,50 @@
-module(benchmark).
-module(benchmark_counter).

-export([run/2,
-export([run/0,
run_multi/2,
run_semimulti/2
]).
-compile(inline).

-define(COUNT, 3 * 1000*1000).
-define(TIMEOUT, 3000*1000).
-define(TIMEOUT, 100*1000).
-define(MILLION, 1000*1000).
-define(MILLIONS(C), C * ?MILLION).

run(Pids, Count) ->
setup() ->
prometheus:start(),
prometheus_counter:declare([{name, test_counter},
{help, ""}]),
{help, ""}]).

run() ->
io:format("Setting up environment~n"),
setup(),
io:format("Finished~n"),
run_single_counter().

run_single_counter() ->

prometheus_counter:reset(test_counter),

run_test(1, ?MILLIONS(1), ?MILLIONS(1)),
run_test(5, ?MILLIONS(1), ?MILLIONS(6)),
run_test(10, ?MILLIONS(1), ?MILLIONS(16)),
run_test(100, ?MILLIONS(1), ?MILLIONS(116)),

io:format("Finished~n").

run_test(Pids, Count, ExpectedValue) ->
io:format("Running single counter benchmark:~n"
" Pids: ~p~n"
" Iterations: ~p~n"
" Expected Value: ~p~n", [Pids, Count, ExpectedValue]),
{Time, _} = timer:tc(fun() -> run_int(Pids, Count) end),
io:format(" Duration (sec): ~p~n", [Time / 1000000]),
Value = case prometheus_counter:value(test_counter) of
ExpectedValue -> color:greenb(io_lib:format("~p", [ExpectedValue]));
CValue -> color:redb(io_lib:format("~p", [CValue]))
end,
io:format(" Counter value: ~s~n", [Value]),
{Time, prometheus_counter:value(test_counter)}.

run_int(PCount, Count) ->
Expand All @@ -36,13 +66,12 @@ loop(Mgr, N, Name) ->
prometheus_counter:inc(Name, 1),
loop(Mgr, N-1, Name).


multi_counter_name(N) ->
list_to_binary(io_lib:format("counter_~p", [N])).

init_multi_counter(N) ->
init_multi_counter(N) ->
prometheus_counter:declare([{name, multi_counter_name(N)},
{help, ""}]),
{help, ""}]),
prometheus_counter:reset(multi_counter_name(N)).

run_multi(Pids, Count) ->
Expand Down Expand Up @@ -74,23 +103,4 @@ run_int_semimulti(PCount, Count) ->
collect(Pids).

floor(X,Y) ->
+ trunc((X - (X rem Y)) / Y).

%% run(CoreCount) ->
%% Mgr = self(),
%% Pids = [spawn_link(fun() -> loop(Mgr, ?COUNT) end) || _ <- lists:seq(1, CoreCount)],
%% collect(Pids).

%% collect([]) -> ok;
%% collect([Pid | Pids]) ->
%% receive
%% {ok, Pid} -> collect(Pids)
%% after ?TIMEOUT ->
%% {error, timeout}
%% end.

%% loop(Mgr, 0) ->
%% Mgr ! {ok, self()};
%% loop(Mgr, N) ->
%% prometheus_counter:dinc(test_counter),
%% loop(Mgr, N-1).
trunc((X - (X rem Y)) / Y).
6 changes: 5 additions & 1 deletion rebar.config
Expand Up @@ -11,6 +11,7 @@
{o_hrl, "include"},
defs_as_proplists, strings_as_binaries, type_specs]}.
{deps, []}.
{shell, [{apps, [prometheus]}]}.
{cover_enabled, true}.
{cover_export_enabled, true}.
{cover_excl_mods, [prometheus_model, %% auto-generated from model.proto
Expand All @@ -33,4 +34,7 @@
{overview, "doc/overview.md"},
{top_level_readme,
{"./README.md",
"https://github.com/deadtrickster/prometheus.erl"}}]}]}]}.
"https://github.com/deadtrickster/prometheus.erl"}}]}]},
{benchmark, [{src_dirs, ["src", "benchmark"]},
{deps, [{'erlang-color',
{git, "https://github.com/julianduque/erlang-color", {branch, "master"}}}]}]}]}.

0 comments on commit ee0ba47

Please sign in to comment.