Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add an appropriate performance test for issue #55

  • Loading branch information...
commit 3a43ca903213ac9b408253fa0cede6c01c9bf560 1 parent 3cf3a84
@kostis kostis authored
Showing with 62 additions and 3 deletions.
  1. +41 −0 test/perf_max_size.erl
  2. +21 −3 test/proper_tests.erl
View
41 test/perf_max_size.erl
@@ -0,0 +1,41 @@
+%%---------------------------------------------------------------------------
+%% From: Jeff Hlywa
+%% Subject: Increasing max_size significantly degrades performance.
+%%---------------------------------------------------------------------------
+%% Using the code below I get:
+%% 1> timer:tc(fun() ->
+%% proper:quickcheck(prop_identity(), [5, {max_size, 42}]) end).
+%% .....
+%% OK: Passed 5 test(s).
+%% {8170,true}
+%%
+%% 2> timer:tc(fun() ->
+%% proper:quickcheck(prop_identity(), [5, {max_size, 16#ffffffff}]) end).
+%% ....
+%% OK: Passed 5 test(s).
+%% {658751072,true}
+%%
+%% Not able to determine the cause of the slowdown, but it's significant.
+%% ---------------------------------------------------------------------------
+%% Fixed on 29/3/2013. The fix was that when increasing the size, move
+%% to the next value immediately instead of trying each value one-by-one.
+%% ---------------------------------------------------------------------------
+-module(perf_max_size).
+-export([prop_identity/0]).
+
+-include_lib("proper/include/proper.hrl").
+
+-record(msg, {a = 0 :: 0..16#ffffffff, b = 0 :: 0..16#f}).
+-type msg() :: #msg{}.
+
+prop_identity() ->
+ ?FORALL(Msg, msg(), Msg =:= decode(encode(Msg))).
+
+-spec encode(msg()) -> binary().
+encode(#msg{a = A, b = B}) ->
+ <<A:32, B:4>>.
+
+-spec decode(binary()) -> msg().
+decode(<<A:32, B:4>>) ->
+ #msg{a=A, b=B}.
+
View
24 test/proper_tests.erl
@@ -1,4 +1,4 @@
-%%% Copyright 2010-2011 Manolis Papadakis <manopapad@gmail.com>,
+%%% Copyright 2010-2013 Manolis Papadakis <manopapad@gmail.com>,
%%% Eirini Arvaniti <eirinibob@gmail.com>
%%% and Kostis Sagonas <kostis@cs.ntua.gr>
%%%
@@ -17,7 +17,7 @@
%%% You should have received a copy of the GNU General Public License
%%% along with PropEr. If not, see <http://www.gnu.org/licenses/>.
-%%% @copyright 2010-2011 Manolis Papadakis, Eirini Arvaniti and Kostis Sagonas
+%%% @copyright 2010-2013 Manolis Papadakis, Eirini Arvaniti and Kostis Sagonas
%%% @version {@version}
%%% @author Manolis Papadakis
%%% @doc This modules contains PropEr's Unit tests. You need the EUnit
@@ -774,7 +774,7 @@ native_type_props_test_() ->
?_passes(weird_types:prop_export_all_works()),
?_passes(weird_types:prop_no_auto_import_works())].
--type bin4() :: <<_:32>>.
+-type bin4() :: <<_:32>>.
-type bits42() :: <<_:42>>.
-type bits5x() :: <<_:_*5>>.
-type bits7x() :: <<_:_*7>>.
@@ -1095,6 +1095,24 @@ dollar_only_cp_test_() ->
%%------------------------------------------------------------------------------
+%% Performance tests
+%%------------------------------------------------------------------------------
+
+max_size_test() ->
+ %% issue a call to load the test module and ensure the test exists
+ true = lists:member({prop_identity,0}, perf_max_size:module_info(exports)),
+ %% run some tests with a small and a big max_size option
+ {Ts,true} = timer:tc(fun() -> max_size_test_aux(42) end),
+ {Tb,true} = timer:tc(fun() -> max_size_test_aux(16#ffffffff) end),
+ %% ensure that the test with the big max_size option does not take
+ %% much longer than the small one to complete
+ ?assertEqual(true, 2*Ts >= Tb).
+
+max_size_test_aux(Size) ->
+ proper:quickcheck(perf_max_size:prop_identity(), [5,{max_size,Size}]).
+
+
+%%------------------------------------------------------------------------------
%% Helper Predicates
%%------------------------------------------------------------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.