diff options
author | Thomas Depierre <depierre.thomas@gmail.com> | 2021-01-18 15:34:12 +0100 |
---|---|---|
committer | Thomas Depierre <depierre.thomas@gmail.com> | 2021-01-18 16:15:32 +0100 |
commit | 60593fdeac560357e8c392aeb8ad893a4e159c8c (patch) | |
tree | a3a8be61652a8e7961b54433f8405f2e8ea9d93f /lib/stdlib/test/stdlib_bench_SUITE.erl | |
parent | e0e9d8bad472fa94f4919e6db798e45913dc9eec (diff) | |
download | erlang-60593fdeac560357e8c392aeb8ad893a4e159c8c.tar.gz |
Add a benchmark for io_lib_format:fwrite_g/1 with random doubles
Diffstat (limited to 'lib/stdlib/test/stdlib_bench_SUITE.erl')
-rw-r--r-- | lib/stdlib/test/stdlib_bench_SUITE.erl | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/stdlib/test/stdlib_bench_SUITE.erl b/lib/stdlib/test/stdlib_bench_SUITE.erl index 3456442088..713c614ec2 100644 --- a/lib/stdlib/test/stdlib_bench_SUITE.erl +++ b/lib/stdlib/test/stdlib_bench_SUITE.erl @@ -29,7 +29,7 @@ suite() -> [{ct_hooks,[{ts_install_cth,[{nodenames,2}]}]}]. all() -> - [{group,unicode},{group,base64},{group,binary}, + [{group,unicode},{group,base64},{group,binary},{group, io}, {group,gen_server},{group,gen_statem}, {group,gen_server_comparison},{group,gen_statem_comparison}]. @@ -52,6 +52,7 @@ groups() -> encode_list, encode_list_to_string, mime_binary_decode, mime_binary_decode_to_string, mime_list_decode, mime_list_decode_to_string]}, + {io, [{repeat, 5}], [double_random_to_list]}, {gen_server, [{repeat,5}], cases(gen_server)}, {gen_statem, [{repeat,3}], cases(gen_statem)}, {gen_server_comparison, [], @@ -279,6 +280,33 @@ mbb(N, Acc) -> B = list_to_binary(lists:seq(0, N-1)), lists:reverse(Acc, B). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +-define(MAX_DOUBLE, (1 bsl 62) - 1). +-define(DOUBLE_SAMPLE, 10000). + +double_random_to_list(_Config) -> + comment(test_double(io_lib_format, fwrite_g)). + +double() -> + Int = rand:uniform(?MAX_DOUBLE), + <<F:64/float>> = <<Int:64/unsigned-integer>>, + F. + +test_double(Mod, Fun) -> + test_double(?DOUBLE_SAMPLE, Mod, Fun). +test_double(Iter, Mod, Fun) -> + F = fun() -> loop_double(Iter, Mod, Fun) end, + {Time, ok} = timer:tc(fun() -> lspawn(F) end), + report_mfa(Iter, Time, Mod). + +loop_double(0, _M, _F) -> garbage_collect(), ok; +loop_double(N, M, F) -> + _ = apply(M, F, [double()]), + loop_double(N - 1, M, F). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + simple(Config) when is_list(Config) -> comment(do_tests(simple, single_small, Config)). |