Add benchmark test for Blake2b

This commit is contained in:
Hans Svensson 2019-02-25 15:18:57 +01:00
parent b70d59333b
commit d242c8c764

View File

@ -24,6 +24,23 @@ blake2s_test_() ->
blake2s(_TC = #{in := Msg, key := Key, out := ExpectedOut}) ->
?assertEqual(eblake2:blake2s(byte_size(ExpectedOut), Msg, Key), {ok, ExpectedOut}).
benchmark_test() ->
%% Benchmark Blake2b against enacl.
#{in := In, key := <<>>, out := Exp} = hd(filter_test_vectors(<<"blake2b">>)),
HashLen = byte_size(Exp),
{T1, _} = timer:tc(fun() -> [ {ok, Exp} = enacl:generichash(HashLen, In) || _ <- lists:seq(1, 500) ] end),
{T2, _} = timer:tc(fun() -> [ {ok, Exp} = eblake2:blake2b(HashLen, In) || _ <- lists:seq(1, 500) ] end),
?debugFmt("~.2f ms compared to ~.2f ms\n", [T1 / 1000, T2 / 1000]),
BigData = <<0:(1024*10)>>,
{T3, _} = timer:tc(fun() -> [ {ok, _} = enacl:generichash(HashLen, BigData) || _ <- lists:seq(1, 50) ] end),
{T4, _} = timer:tc(fun() -> [ {ok, _} = eblake2:blake2b(HashLen, BigData) || _ <- lists:seq(1, 50) ] end),
?debugFmt("~.2f ms compared to ~.2f ms\n", [T3 / 1000, T4 / 1000]),
ok.
random_test_() ->
{generator, fun() ->