summaryrefslogtreecommitdiff
path: root/bench.erl
diff options
context:
space:
mode:
Diffstat (limited to 'bench.erl')
-rwxr-xr-xbench.erl90
1 files changed, 90 insertions, 0 deletions
diff --git a/bench.erl b/bench.erl
new file mode 100755
index 0000000..9fa0651
--- /dev/null
+++ b/bench.erl
@@ -0,0 +1,90 @@
+#!/usr/bin/env escript
+%% -*- erlang -*-
+%%! -pa test/ebin -pa ../lager/ebin -pa ../lager/deps/goldrush/ebin
+
+add_entries(Entries) ->
+ lists:foreach(fun (Entry) ->
+ ht:add(Entry)
+ end, Entries).
+
+heapsize(Pid) when is_pid(Pid) ->
+ {total_heap_size, TotalHeapSize} = erlang:process_info(Pid, total_heap_size),
+ io_lib:format("~.2f M", [TotalHeapSize*8/1024/1024]);
+heapsize(Name) when is_atom(Name) ->
+ heapsize(whereis(Name)).
+
+timeprint(Time) ->
+ io_lib:format("~.2fs", [Time/1000000]).
+
+printheapsize() ->
+ case false of
+ true ->
+ io:format("Heap size: local ~s ht ~s~n", [heapsize(self()), heapsize(ht)]);
+ false ->
+ none
+ end.
+
+main(_) ->
+ %%eprof:start(),
+ lager:start(),
+ lager:set_loglevel(lager_console_backend, debug),
+ FirstBatch = 5000000,
+ SecondBatch = 5000000,
+ ThirdBatch = 1000000,
+
+ LagerPath = "ebin",
+ case code:add_path(LagerPath) of
+ true ->
+ ok;
+ {error, bad_directory} ->
+ io:format("Could not add path ~p~n", [LagerPath]),
+ halt(1)
+ end,
+ ht:start_link(),
+
+ printheapsize(),
+ %%eprof:start_profiling([ht]),
+ {Time1, _Tree} = timer:tc(fun () -> ht:reset_tree([FirstBatch]) end),
+ %%eprof:stop_profiling(),
+ io:format("Init with ~p entries: ~s~n", [FirstBatch+1, timeprint(Time1)]),
+ printheapsize(),
+
+ {Time2a, _} = timer:tc(fun () -> ht:root(FirstBatch div 2) end),
+ io:format("Build half tree: ~s~n", [timeprint(Time2a)]),
+ printheapsize(),
+ {Time2b, _} = timer:tc(fun () -> ht:root(FirstBatch - 10) end),
+ io:format("Build almost whole tree: ~s~n", [timeprint(Time2b)]),
+ printheapsize(),
+ {Time2c, _} = timer:tc(fun () -> ht:root() end),
+ io:format("Build whole tree: ~s~n", [timeprint(Time2c)]),
+ printheapsize(),
+ {Time2d, _} = timer:tc(fun () -> ht:root() end),
+ io:format("Build tree again: ~s~n", [timeprint(Time2d)]),
+ printheapsize(),
+ io:format("treesize: ~p~n", [ht:size()]),
+
+ {Time3, _} = timer:tc(fun () -> ht:load_tree(FirstBatch + SecondBatch) end),
+ io:format("Load up to ~p entries: ~s~n", [FirstBatch + SecondBatch + 1, timeprint(Time3)]),
+ printheapsize(),
+
+ {Time4c, _} = timer:tc(fun () -> ht:root() end),
+ io:format("Build whole tree: ~s~n", [timeprint(Time4c)]),
+ printheapsize(),
+ {Time4d, _} = timer:tc(fun () -> ht:root() end),
+ io:format("Build tree again: ~s~n", [timeprint(Time4d)]),
+ printheapsize(),
+ io:format("treesize: ~p~n", [ht:size()]),
+
+
+ Entries2 = lists:map(fun (_) -> <<"bar">> end, lists:seq(1, ThirdBatch)),
+ {Time5, _} = timer:tc(fun () -> add_entries(Entries2) end),
+ io:format("Add ~p entries: ~s~n", [length(Entries2), timeprint(Time5)]),
+ printheapsize(),
+ {Time6, _} = timer:tc(fun () -> ht:root() end),
+ io:format("Build tree: ~s~n", [timeprint(Time6)]),
+ printheapsize(),
+ garbage_collect(self()),
+ garbage_collect(whereis(ht)),
+ printheapsize(),
+ %%eprof:analyze(),
+ ok.