aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/test
diff options
context:
space:
mode:
authorHenrik Nord <[email protected]>2014-11-20 10:34:38 +0100
committerHenrik Nord <[email protected]>2014-11-20 10:34:38 +0100
commita881aaf73a7c0f102175aa837679c62976575fa1 (patch)
tree855e3e87036ed44f392a1a6abfe721c4e7263031 /lib/stdlib/test
parent91be6bd0aa5f5077506208dade8952bca8434aea (diff)
parentcb372c96f3449cfca69e2737fa3d4503fa24444a (diff)
downloadotp-a881aaf73a7c0f102175aa837679c62976575fa1.tar.gz
otp-a881aaf73a7c0f102175aa837679c62976575fa1.tar.bz2
otp-a881aaf73a7c0f102175aa837679c62976575fa1.zip
Merge branch 'maint'
Diffstat (limited to 'lib/stdlib/test')
-rw-r--r--lib/stdlib/test/io_SUITE.erl46
1 files changed, 44 insertions, 2 deletions
diff --git a/lib/stdlib/test/io_SUITE.erl b/lib/stdlib/test/io_SUITE.erl
index 3a76275f31..2203dd8f51 100644
--- a/lib/stdlib/test/io_SUITE.erl
+++ b/lib/stdlib/test/io_SUITE.erl
@@ -30,7 +30,8 @@
io_fread_newlines/1, otp_8989/1, io_lib_fread_literal/1,
printable_range/1,
io_lib_print_binary_depth_one/1, otp_10302/1, otp_10755/1,
- otp_10836/1, io_lib_width_too_small/1]).
+ otp_10836/1, io_lib_width_too_small/1,
+ io_with_huge_message_queue/1]).
-export([pretty/2]).
@@ -70,7 +71,7 @@ all() ->
io_fread_newlines, otp_8989, io_lib_fread_literal,
printable_range,
io_lib_print_binary_depth_one, otp_10302, otp_10755, otp_10836,
- io_lib_width_too_small].
+ io_lib_width_too_small, io_with_huge_message_queue].
groups() ->
[].
@@ -2219,3 +2220,44 @@ io_lib_width_too_small(Config) ->
"**" = lists:flatten(io_lib:format("~2.3w", [3.14])),
"**" = lists:flatten(io_lib:format("~2.5w", [3.14])),
ok.
+
+%% Test that the time for a huge message queue is not
+%% significantly slower than with an empty message queue.
+io_with_huge_message_queue(Config) when is_list(Config) ->
+ case test_server:is_native(gen) of
+ true ->
+ {skip,
+ "gen is native - huge message queue optimization "
+ "is not implemented"};
+ false ->
+ do_io_with_huge_message_queue(Config)
+ end.
+
+do_io_with_huge_message_queue(Config) ->
+ PrivDir = ?privdir(Config),
+ File = filename:join(PrivDir, "slask"),
+ {ok, F1} = file:open(File, [write]),
+
+ {Time,ok} = timer:tc(fun() -> writes(1000, F1) end),
+
+ [self() ! {msg,N} || N <- lists:seq(1, 500000)],
+ erlang:garbage_collect(),
+ {NewTime,ok} = timer:tc(fun() -> writes(1000, F1) end),
+ file:close(F1),
+ io:format("Time for empty message queue: ~p", [Time]),
+ io:format("Time for huge message queue: ~p", [NewTime]),
+
+ IsCover = test_server:is_cover(),
+ case (NewTime+1) / (Time+1) of
+ Q when Q < 10; IsCover ->
+ ok;
+ Q ->
+ io:format("Q = ~p", [Q]),
+ ?t:fail()
+ end,
+ ok.
+
+writes(0, _) -> ok;
+writes(N, F1) ->
+ file:write(F1, "hello\n"),
+ writes(N - 1, F1).