Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(simple_counter1).
- -export([count_to/1, increment/2, test/0]).
- count_to(Target) ->
- increment(0, Target).
- increment(Target, Target) ->
- Target;
- increment(Count, Target) ->
- increment(Count + 1, Target).
- test() ->
- p("bench", {result, benchmark_elements()}),
- TenEighth = round(math:pow(10,8)),
- lists:map(fun(Target) ->
- p("bench", benchmark(fun () -> count_to(Target) end))
- end,
- lists:map(fun (E) -> round(math:pow(10,E)) end, lists:seq(4,7))
- ++ lists:seq(TenEighth, 8*TenEighth, TenEighth)
- ).
- p(Label, Message) ->
- io:format("~s: ~p~n", [Label, Message]).
- benchmark(TargetFunction) ->
- lists:foreach(fun statistics/1, benchmark_elements()),
- Result = TargetFunction(),
- Times = lists:map(
- fun (Type) -> {_, T} = statistics(Type), T end,
- benchmark_elements()
- ),
- {Result, Times}.
- benchmark_elements() ->
- [runtime, wall_clock].
Add Comment
Please, Sign In to add comment