diff options
| author | Magnus Ahltorp <map@kth.se> | 2014-10-30 16:19:39 +0100 |
|---|---|---|
| committer | Magnus Ahltorp <map@kth.se> | 2014-10-30 16:19:39 +0100 |
| commit | c9d24a8a6a58590f47ecf3104efd94d8125e5a64 (patch) | |
| tree | c22ba6a96947604ac8282ed2a0ec5be1a98e261c | |
| parent | bbcb238f5232fc29da7d4cb215d2316bd4421b8c (diff) | |
Rough benchmark of ht
| -rwxr-xr-x | bench.erl | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/bench.erl b/bench.erl new file mode 100755 index 0000000..7493abd --- /dev/null +++ b/bench.erl @@ -0,0 +1,48 @@ +#!/usr/bin/env escript +%% -*- erlang -*- + +add_entries(Entries) -> + lists:foreach(fun (Entry) -> + ht:add(Entry) + end, Entries). + +main(_) -> + FirstBatch = 5000000, + SecondBatch = 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(), + Entries = lists:map(fun (_) -> <<"bar">> end, lists:seq(1, FirstBatch)), + + io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), + {Time1, Tree} = timer:tc(fun () -> ht:new(Entries) end), + io:format("Init with ~p entries: ~p~n", [length(Entries), Time1]), + io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), + {Time2, {BuiltTree, _RootHash}} = timer:tc(fun () -> ht:root(Tree, length(Entries) - 1) end), + io:format("Build tree: ~p~n", [Time2]), + io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), + {TimeChange, _} = timer:tc(fun () -> ht:change_tree(BuiltTree) end), + io:format("Change tree: ~p~n", [TimeChange]), + io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), + {Time2b, _} = timer:tc(fun () -> ht:root() end), + io:format("Build tree: ~p~n", [Time2b]), + io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), + io:format("treesize: ~p~n", [ht:size()]), + Entries2 = lists:map(fun (_) -> <<"bar">> end, lists:seq(1, SecondBatch)), + {Time3, _} = timer:tc(fun () -> add_entries(Entries2) end), + io:format("Add ~p entries ~p~n", [length(Entries2), Time3]), + io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), + {Time4, _} = timer:tc(fun () -> ht:root() end), + io:format("Build tree: ~p~n", [Time4]), + io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), + garbage_collect(self()), + garbage_collect(whereis(ht)), + io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), + ok. |
