File: perf_max_size.erl

package info (click to toggle)
erlang-proper 1.2%2Bgit988ea0ed9f%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 992 kB
  • sloc: erlang: 11,684; sh: 65; makefile: 49
file content (44 lines) | stat: -rw-r--r-- 1,449 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
%%---------------------------------------------------------------------------
%% From: Jeff Hlywa
%% Subject: Increasing max_size significantly degrades performance.
%%---------------------------------------------------------------------------
%% Using the code below I get:
%% 1> timer:tc(fun() ->
%%      proper:quickcheck(perf_max_size:prop_identity(), [5, {max_size, 42}])
%%    end).
%% .....
%% OK: Passed 5 test(s).
%% {8170,true}
%%
%% 2> timer:tc(fun() ->
%%      proper:quickcheck(perf_max_size: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()) -> bitstring().
encode(#msg{a = A, b = B}) ->
    <<A:32, B:4>>.

-spec decode(bitstring()) -> msg().
decode(<<A:32, B:4>>) ->
    #msg{a = A, b = B}.