Guest User

Untitled

a guest
Feb 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. -module(simple_counter1).
  2. -export([count_to/1, increment/2, test/0]).
  3.  
  4. count_to(Target) ->
  5. increment(0, Target).
  6.  
  7. increment(Target, Target) ->
  8. Target;
  9. increment(Count, Target) ->
  10. increment(Count + 1, Target).
  11.  
  12. test() ->
  13. p("bench", {result, benchmark_elements()}),
  14. TenEighth = round(math:pow(10,8)),
  15. lists:map(fun(Target) ->
  16. p("bench", benchmark(fun () -> count_to(Target) end))
  17. end,
  18. lists:map(fun (E) -> round(math:pow(10,E)) end, lists:seq(4,7))
  19. ++ lists:seq(TenEighth, 8*TenEighth, TenEighth)
  20. ).
  21.  
  22. p(Label, Message) ->
  23. io:format("~s: ~p~n", [Label, Message]).
  24.  
  25. benchmark(TargetFunction) ->
  26. lists:foreach(fun statistics/1, benchmark_elements()),
  27. Result = TargetFunction(),
  28. Times = lists:map(
  29. fun (Type) -> {_, T} = statistics(Type), T end,
  30. benchmark_elements()
  31. ),
  32. {Result, Times}.
  33.  
  34. benchmark_elements() ->
  35. [runtime, wall_clock].
Add Comment
Please, Sign In to add comment