Skip to content

Commit

Permalink
Add test option to run collissions only and related scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
jvirkki committed Sep 18, 2015
1 parent 8ac4627 commit 2bced81
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 7 deletions.
2 changes: 2 additions & 0 deletions misc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data
data.cmp
10 changes: 10 additions & 0 deletions misc/1.0/linux.10000.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1000, 0
2000, 0.24
3000, 1.44
4000, 5.16
5000, 15.24
6000, 34.2
7000, 63.96
8000, 113.92
9000, 175.72
10000, 269.24
10 changes: 10 additions & 0 deletions misc/1.0/linux.100000.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
10000, 0.16
20000, 2.64
30000, 15.32
40000, 60.36
50000, 158.32
60000, 336.48
70000, 649.32
80000, 1109.2
90000, 1784.48
100000, 2691.52
10 changes: 10 additions & 0 deletions misc/1.0/linux.10000000.001
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1000000, 0
2000000, 0
3000000, 0.04
4000000, 0.32
5000000, 2.6
6000000, 13.96
7000000, 57
8000000, 184.36
9000000, 509.52
10000000, 1210.56
10 changes: 10 additions & 0 deletions misc/1.0/linux.10000000.01
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1000000, 0
2000000, 0.12
3000000, 4.8
4000000, 39.12
5000000, 180.68
6000000, 620.88
7000000, 1749.44
8000000, 4168.48
9000000, 8716.72
10000000, 16666.44
10 changes: 10 additions & 0 deletions misc/1.0/linux.10000000.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1000000, 8.96
2000000, 240.44
3000000, 1561.84
4000000, 5801.16
5000000, 15577.6
6000000, 34093.12
7000000, 64954.48
8000000, 112030.32
9000000, 178613.72
10000000, 268721.6
10 changes: 10 additions & 0 deletions misc/1.0/solaris.10000.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1000, 0
2000, 0.48
3000, 1.4
4000, 5.24
5000, 15.84
6000, 33.68
7000, 68.12
8000, 110.6
9000, 178.96
10000, 268.84
10 changes: 10 additions & 0 deletions misc/1.0/solaris.100000.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
10000, 0.08
20000, 2.44
30000, 18.16
40000, 59.88
50000, 151.84
60000, 342.52
70000, 656.04
80000, 1113.56
90000, 1795.76
100000, 2690.04
10 changes: 10 additions & 0 deletions misc/1.0/solaris.10000000.001
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1000000, 0
2000000, 0
3000000, 0.04
4000000, 0.24
5000000, 3.44
6000000, 12.84
7000000, 55.8
8000000, 183.88
9000000, 493.92
10000000, 1224.08
10 changes: 10 additions & 0 deletions misc/1.0/solaris.10000000.01
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1000000, 0
2000000, 0.36
3000000, 4.04
4000000, 38.52
5000000, 175.08
6000000, 631.96
7000000, 1764.8
8000000, 4164.16
9000000, 8780.44
10000000, 16635.36
10 changes: 10 additions & 0 deletions misc/1.0/solaris.10000000.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1000000, 7.44
2000000, 231.64
3000000, 1567.76
4000000, 5794.88
5000000, 15564.04
6000000, 34060.92
7000000, 64926.88
8000000, 111990.88
9000000, 178743
10000000, 268803.76
51 changes: 51 additions & 0 deletions misc/colcmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env perl

#
# Copyright (c) 2015, Jyri J. Virkki
# All rights reserved.
#
# This file is under BSD license. See LICENSE file.
#

#
# ./colcmp FILE1 FILE2
#
# Compare two collision average runs (generated with colgraph).
# The runs must be for the same SIZE (see colgraph).
#
# Requires ploticus to generate the graph.
#

$file1 = shift(@ARGV);
$file2 = shift(@ARGV);

if (! -e $file1 || ! -e $file2) {
die "File not found\n";
}

open(F1, $file1);
open(F2, $file2);
open(OUT, ">data.cmp");

while(<F1>) {
($count1, $avg1) = /(\d+), (\S+)/;
$_ = <F2>;
($count2, $avg2) = /(\d+), (\S+)/;
if ($count1 ne $count2) {
die "mismatch $count1 $count2\n";
}
print OUT "$count2 $avg1 $avg2\n";
}

close(F1);
close(F2);
close(OUT);

$cmd = "ploticus -prefab lines data=data.cmp x=1 y=2 y2=3 " .
"\"xrange=0 $count2\" \"title=size = $count2\" " .
"\"ylbl=collisions\" \"xlbl=count\" \"name=$file1\" " .
"\"name2=$file2\" ";
print "$cmd\n";
system($cmd);

unlink "data.cmp";
58 changes: 58 additions & 0 deletions misc/colgraph
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env perl

#
# Copyright (c) 2015, Jyri J. Virkki
# All rights reserved.
#
# This file is under BSD license. See LICENSE file.
#

#
# ./colgraph SIZE ERROR
#
# SIZE = size of bloom library to initialize
# ERROR = expected error
#
# This script runs a random collision test (test-libbloom -c) $rounds
# number of times for 10 element counts from SIZE/10 to SIZE. The
# average of each run is saved in the 'data' file in the current
# directory.
#
# If ploticus is available it'll also display a graph. Or you can use
# any other graphing app or tool to process the 'data' file.
#

$rounds = 25;

$size = shift(@ARGV);
if (!$size) {
die "provide a size\n";
}

$error = shift(@ARGV);
if (!$error) {
die "provide expected error\n";
}

open(OUT, ">data");
for ($tenth = 1; $tenth < 11; $tenth++) {
$count = ($size / 10) * $tenth;

$avg = 0;
for ($n = 0; $n < $rounds; $n++) {
open(RES, "../build/test-libbloom -c $size $error $count |");
while(<RES>) {$got = $_;}
close(RES);
($added, $coll) = $got =~ /added (\d+), collisions (\d+)/;
$avg += $coll;
}
$avg /= $rounds;
print "ADDED $added, AVG.COLL $avg\n";
print OUT "$added, $avg\n";
}
close(OUT);

$cmd = "ploticus -prefab lines data=data x=1 y=2 \"xrange=0 $size\" " .
"\"title=size = $size\" \"ylbl=collisions\" \"xlbl=count\" ";
print "$cmd\n";
system($cmd);
27 changes: 20 additions & 7 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,7 @@ static void add_random(int entries, double error, int count)
(void)close(fd);
bloom_free(&bloom);

(void)printf("added %d elements, got %d collisions\n", count, collisions);

if (count <= entries) {
assert(collisions <= (entries * error));
} else if (count <= entries * 2) {
assert(collisions < (2 * entries * error));
}
(void)printf("added %d, collisions %d\n", count, collisions);
}


Expand Down Expand Up @@ -127,6 +121,18 @@ static void perf_loop(int entries, int count)
/** ***************************************************************************
* main...
*
* To test performance only, run with options: -p ENTRIES COUNT
* Where 'ENTRIES' is the expected number of entries used to initialize the
* bloom filter and 'COUNT' is the actual number of entries inserted.
*
* To test collisions, run with options: -c ENTRIES ERROR COUNT
* Where 'ENTRIES' is the expected number of entries used to initialize the
* bloom filter and 'ERROR' is the acceptable probability of collision
* used to initialize the bloom filter. 'COUNT' is the actual number of
* entries inserted.
*
* With no options, it runs various tests.
*
*/
int main(int argc, char **argv)
{
Expand All @@ -137,6 +143,11 @@ int main(int argc, char **argv)
exit(0);
}

if (argc == 5 && !strncmp(argv[1], "-c", 2)) {
add_random(atoi(argv[2]), atof(argv[3]), atoi(argv[4]));
exit(0);
}

basic();
add_random(100, 0.001, 300);

Expand All @@ -146,4 +157,6 @@ int main(int argc, char **argv)
}

perf_loop(10000000, 10000000);

printf("\nBrought to you by libbloom-%s\n", bloom_version());
}

0 comments on commit 2bced81

Please sign in to comment.