-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertiontest.cpp
67 lines (54 loc) · 1.43 KB
/
insertiontest.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Tests speed benefits of adding keys
* @author Jonah Kallenbach
* @author Ankit Gupta
*
*/
#include <iostream>
#include <string>
#include <set>
#include <functional>
#include <map>
#include <time.h>
#include <assert.h>
#include <stdlib.h>
#include "cuckoorings.hpp"
using namespace std;
int main ()
{
// initialize variables and seed the random number generator
clock_t t1, t2, t3;
srand (time(NULL));
int i, j;
// repeat the experiment several times
for (int repeat = 1; repeat < 4; ++repeat) {
for (j = 100000; j <= 2000000; j += 100000) {
// initialize the data structures
RingHash r((1L << 32), 1000000);
CuckooRings c((1L << 32), 500000);
// begin timing the RingHash
t1 = clock();
// make the insertions
for (i = 1; i <= j; ++i) {
r.insert(i);
}
t2 = clock();
// print statistics
cout << ((float)(t2-t1))/CLOCKS_PER_SEC << ",";
cout << ((float) r.cost_of_structure()) / r.getNumServers() << ",";
cout << r.get_max_load() << endl;
// reset the clock
t1 = clock();
// make the insertions into the CuckooRings
for (i = 1; i <= j; ++i) {
c.insert(i);
}
t2 = clock();
// print statistics
cout << ((float)(t2-t1))/CLOCKS_PER_SEC << ",";
cout << ((float) c.cost_of_structure()) / c.getNumServers() << ",";
cout << c.get_max_load() << endl;
}
}
return 0;
}