diff options
-rw-r--r-- | Emakefile | 5 | ||||
-rwxr-xr-x | bench.erl | 90 | ||||
-rw-r--r-- | test/src/db.erl | 18 |
3 files changed, 113 insertions, 0 deletions
@@ -4,3 +4,8 @@ {i, "include/"}, {outdir, "ebin/"}, {parse_transform, lager_transform}]}. +{["test/src/*"], + [debug_info, + {i, "include/"}, + {outdir, "test/ebin/"}, + {parse_transform, lager_transform}]}. 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. diff --git a/test/src/db.erl b/test/src/db.erl new file mode 100644 index 0000000..8c90842 --- /dev/null +++ b/test/src/db.erl @@ -0,0 +1,18 @@ +%%% Copyright (c) 2014, NORDUnet A/S. +%%% See LICENSE for licensing information. + +-module(db). +-export([get_by_indices/3]). + +get_by_indices(Start, _End, _Options) when Start < 0 -> + []; +get_by_indices(Start, End, _Options) -> + case Start =< End of + true -> + B = crypto:hash(sha256, <<"bar">>), + lists:map(fun (Index) -> + {Index, B, notfetched} + end, lists:seq(Start, End)); + false -> + [] + end. |