Further testing of skiplists
Suspected at some stage there was a problem with small lists that never hit a marker. Can't find it yet through test
This commit is contained in:
parent
364527f3b8
commit
39f61db92b
1 changed files with 30 additions and 19 deletions
|
@ -344,7 +344,7 @@ splitlist_end(EndKey, SL) ->
|
||||||
generate_randomkeys(Seqn, Count, BucketRangeLow, BucketRangeHigh) ->
|
generate_randomkeys(Seqn, Count, BucketRangeLow, BucketRangeHigh) ->
|
||||||
generate_randomkeys(Seqn,
|
generate_randomkeys(Seqn,
|
||||||
Count,
|
Count,
|
||||||
gb_trees:empty(),
|
[],
|
||||||
BucketRangeLow,
|
BucketRangeLow,
|
||||||
BucketRangeHigh).
|
BucketRangeHigh).
|
||||||
|
|
||||||
|
@ -364,22 +364,39 @@ generate_randomkeys(Seqn, Count, Acc, BucketLow, BRange) ->
|
||||||
{Seqn, {active, infinity}, null}},
|
{Seqn, {active, infinity}, null}},
|
||||||
generate_randomkeys(Seqn + 1,
|
generate_randomkeys(Seqn + 1,
|
||||||
Count - 1,
|
Count - 1,
|
||||||
gb_trees:enter(K, V, Acc),
|
[{K, V}|Acc],
|
||||||
BucketLow,
|
BucketLow,
|
||||||
BRange).
|
BRange).
|
||||||
|
|
||||||
|
skiplist_small_test() ->
|
||||||
|
% Check nothing bad happens with very small lists
|
||||||
|
lists:foreach(fun(N) -> dotest_skiplist_small(N) end, lists:seq(1, 32)).
|
||||||
|
|
||||||
|
|
||||||
|
dotest_skiplist_small(N) ->
|
||||||
|
KL = generate_randomkeys(1, N, 1, 2),
|
||||||
|
SkipList1 =
|
||||||
|
lists:foldl(fun({K, V}, SL) ->
|
||||||
|
enter(K, V, SL)
|
||||||
|
end,
|
||||||
|
empty(),
|
||||||
|
KL),
|
||||||
|
lists:foreach(fun({K, V}) -> ?assertMatch({value, V}, lookup(K, SkipList1))
|
||||||
|
end,
|
||||||
|
lists:ukeysort(1, lists:reverse(KL))).
|
||||||
|
|
||||||
skiplist_test() ->
|
skiplist_test() ->
|
||||||
N = 8000,
|
N = 8000,
|
||||||
KL = gb_trees:to_list(generate_randomkeys(1, N, 1, N div 5)),
|
KL = generate_randomkeys(1, N, 1, N div 5),
|
||||||
|
|
||||||
SWaGSL = os:timestamp(),
|
SWaGSL = os:timestamp(),
|
||||||
SkipList = from_list(KL),
|
SkipList = from_list(lists:reverse(KL)),
|
||||||
io:format(user, "Generating skip list with ~w keys in ~w microseconds~n" ++
|
io:format(user, "Generating skip list with ~w keys in ~w microseconds~n" ++
|
||||||
"Top level key count of ~w~n",
|
"Top level key count of ~w~n",
|
||||||
[N, timer:now_diff(os:timestamp(), SWaGSL), length(SkipList)]),
|
[N, timer:now_diff(os:timestamp(), SWaGSL), length(SkipList)]),
|
||||||
io:format(user, "Second tier key counts of ~w~n",
|
io:format(user, "Second tier key counts of ~w~n",
|
||||||
[lists:map(fun({_L, SL}) -> length(SL) end, SkipList)]),
|
[lists:map(fun({_L, SL}) -> length(SL) end, SkipList)]),
|
||||||
KLSorted = lists:ukeysort(1, KL),
|
KLSorted = lists:ukeysort(1, lists:reverse(KL)),
|
||||||
|
|
||||||
SWaGSL2 = os:timestamp(),
|
SWaGSL2 = os:timestamp(),
|
||||||
SkipList = from_sortedlist(KLSorted),
|
SkipList = from_sortedlist(KLSorted),
|
||||||
|
@ -402,10 +419,10 @@ skiplist_test() ->
|
||||||
[lists:map(fun({_L, SL}) -> length(SL) end, SkipList1)]),
|
[lists:map(fun({_L, SL}) -> length(SL) end, SkipList1)]),
|
||||||
|
|
||||||
io:format(user, "~nRunning timing tests for generated skiplist:~n", []),
|
io:format(user, "~nRunning timing tests for generated skiplist:~n", []),
|
||||||
skiplist_timingtest(KL, SkipList, N),
|
skiplist_timingtest(KLSorted, SkipList, N),
|
||||||
|
|
||||||
io:format(user, "~nRunning timing tests for dynamic skiplist:~n", []),
|
io:format(user, "~nRunning timing tests for dynamic skiplist:~n", []),
|
||||||
skiplist_timingtest(KL, SkipList1, N).
|
skiplist_timingtest(KLSorted, SkipList1, N).
|
||||||
|
|
||||||
|
|
||||||
skiplist_timingtest(KL, SkipList, N) ->
|
skiplist_timingtest(KL, SkipList, N) ->
|
||||||
|
@ -455,21 +472,18 @@ skiplist_timingtest(KL, SkipList, N) ->
|
||||||
RangeFun(SkipList, CheckList7, true),
|
RangeFun(SkipList, CheckList7, true),
|
||||||
RangeFun(SkipList, CheckList8, true),
|
RangeFun(SkipList, CheckList8, true),
|
||||||
|
|
||||||
KL_OOR1 = gb_trees:to_list(generate_randomkeys(1,
|
KL_OOR1 = generate_randomkeys(1, 4, N div 5 + 1, N div 5 + 10),
|
||||||
4,
|
|
||||||
N div 5 + 1,
|
|
||||||
N div 5 + 10)),
|
|
||||||
KR9 = RangeFun(SkipList, KL_OOR1, false),
|
KR9 = RangeFun(SkipList, KL_OOR1, false),
|
||||||
?assertMatch([], KR9),
|
?assertMatch([], KR9),
|
||||||
|
|
||||||
KL_OOR2 = gb_trees:to_list(generate_randomkeys(1, 4, 0, 0)),
|
KL_OOR2 = generate_randomkeys(1, 4, 0, 0),
|
||||||
KR10 = RangeFun(SkipList, KL_OOR2, false),
|
KR10 = RangeFun(SkipList, KL_OOR2, false),
|
||||||
?assertMatch([], KR10),
|
?assertMatch([], KR10),
|
||||||
|
|
||||||
io:format(user, "Finding 10 ranges took ~w microseconds~n",
|
io:format(user, "Finding 10 ranges took ~w microseconds~n",
|
||||||
[timer:now_diff(os:timestamp(), SWc)]),
|
[timer:now_diff(os:timestamp(), SWc)]),
|
||||||
|
|
||||||
AltKL1 = gb_trees:to_list(generate_randomkeys(1, 1000, 1, 200)),
|
AltKL1 = generate_randomkeys(1, 1000, 1, 200),
|
||||||
SWd = os:timestamp(),
|
SWd = os:timestamp(),
|
||||||
lists:foreach(fun({K, _V}) ->
|
lists:foreach(fun({K, _V}) ->
|
||||||
lookup(K, SkipList)
|
lookup(K, SkipList)
|
||||||
|
@ -477,10 +491,7 @@ skiplist_timingtest(KL, SkipList, N) ->
|
||||||
AltKL1),
|
AltKL1),
|
||||||
io:format(user, "Getting 1000 mainly missing keys took ~w microseconds~n",
|
io:format(user, "Getting 1000 mainly missing keys took ~w microseconds~n",
|
||||||
[timer:now_diff(os:timestamp(), SWd)]),
|
[timer:now_diff(os:timestamp(), SWd)]),
|
||||||
AltKL2 = gb_trees:to_list(generate_randomkeys(1,
|
AltKL2 = generate_randomkeys(1, 1000, N div 5 + 1, N div 5 + 300),
|
||||||
1000,
|
|
||||||
N div 5 + 1,
|
|
||||||
N div 5 + 300)),
|
|
||||||
SWe = os:timestamp(),
|
SWe = os:timestamp(),
|
||||||
lists:foreach(fun({K, _V}) ->
|
lists:foreach(fun({K, _V}) ->
|
||||||
none = lookup(K, SkipList)
|
none = lookup(K, SkipList)
|
||||||
|
@ -489,7 +500,7 @@ skiplist_timingtest(KL, SkipList, N) ->
|
||||||
io:format(user, "Getting 1000 missing keys above range took ~w " ++
|
io:format(user, "Getting 1000 missing keys above range took ~w " ++
|
||||||
"microseconds~n",
|
"microseconds~n",
|
||||||
[timer:now_diff(os:timestamp(), SWe)]),
|
[timer:now_diff(os:timestamp(), SWe)]),
|
||||||
AltKL3 = gb_trees:to_list(generate_randomkeys(1, 1000, 0, 0)),
|
AltKL3 = generate_randomkeys(1, 1000, 0, 0),
|
||||||
SWf = os:timestamp(),
|
SWf = os:timestamp(),
|
||||||
lists:foreach(fun({K, _V}) ->
|
lists:foreach(fun({K, _V}) ->
|
||||||
none = lookup(K, SkipList)
|
none = lookup(K, SkipList)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue