Skip to content

Instantly share code, notes, and snippets.

@cooldaemon
Created December 27, 2009 14:28
Show Gist options
  • Save cooldaemon/264286 to your computer and use it in GitHub Desktop.
Save cooldaemon/264286 to your computer and use it in GitHub Desktop.
-module(fold).
-author('[email protected]').
-export([test/1]).
test(Max) ->
lists:map(
fun (F) ->
benchmark(fun () ->
F(fun (N, Acc) -> N + Acc end, 0, lists:seq(1, Max))
end)
end,
[fun lists:foldl/3, fun lists:foldr/3]
).
benchmark(F) ->
lists:foreach(fun statistics/1, [runtime, wall_clock]),
Result = F(),
Times = lists:map(
fun (Type) -> {_, T} = statistics(Type), T end,
[runtime, wall_clock]
),
{Result, Times}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment