Permalink
Browse files

add benchmark module

  • Loading branch information...
1 parent 19fc7a4 commit c2fc3b28d28256900889affaf802f518af77d31c @martinrehfeld committed May 14, 2012
Showing with 20 additions and 0 deletions.
  1. +20 −0 apps/countdown/src/cd_benchmark.erl
@@ -0,0 +1,20 @@
+-module(cd_benchmark).
+
+-export([run/2, run/3]).
+
+run(Fn, Args) ->
+ Start = now(),
+ apply(Fn, Args),
+ End = now(),
+
+ Runtime = timer:now_diff(End, Start) / 1000,
+ error_logger:info_msg("Run with args ~p took ~p ms~n", [Args, Runtime]),
+ Runtime.
+
+run(Count, Fn, Args) ->
+ TotalRuntime = lists:foldl(fun(_, Total) -> Total + run(Fn, Args) end,
+ 0, lists:seq(1, Count)),
+ AverageRuntime = TotalRuntime / Count,
+ error_logger:info_msg("~p Iterations with args ~p took ~p ms (Avg: ~p ms)~n",
+ [Count, Args, TotalRuntime, AverageRuntime]),
+ TotalRuntime.

0 comments on commit c2fc3b2

Please sign in to comment.