diff options
author | Magnus Ahltorp <map@kth.se> | 2014-10-30 16:19:39 +0100 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2014-11-19 05:04:41 +0100 |
commit | bd098e40e87f5c27813853815d918b59318a95cd (patch) | |
tree | cd0f5c6f383049eeebf8d26cca9dde1d9b4f060a /bench.erl | |
parent | c0efb34c964b47c16855f880593752e52fd57e29 (diff) |
Benchmark of ht
Diffstat (limited to 'bench.erl')
-rwxr-xr-x | bench.erl | 90 |
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. |