-
Notifications
You must be signed in to change notification settings - Fork 0
/
rmservertest.cpp
81 lines (64 loc) · 1.9 KB
/
rmservertest.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Tests speed benefits of removing a server.
* Begin by adding 1000000 items to 1000000 servers. Then remove 0 to 100000 servers (10%) by increments of 5000
* and track the time it takes to do that for CuckooRing and regular Ring.
* @author Ankit Gupta
* @author Jonah Kallenbach
*/
#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 test several times
for (int repeat = 1; repeat < 4; ++repeat) {
for (j = 0; j <= 100000; j += 5000) {
// initialize the data structures
RingHash r((1L << 32), 1000000);
CuckooRings c((1L << 32), 500000);
// begin timing the RingHash
t1 = clock();
// make all of the insertions
for (i = 1; i <= 1000000; ++i) {
r.insert(i);
}
// remove some number of servers randomly
for (i = 0; i <= j; ++i) {
r.remove_random_server();
}
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();
// insert keys into CuckooRings
for (i = 1; i <= 1000000; ++i) {
c.insert(i);
}
// remove servers randomly from each side
for (i = 0; i <= j/2; ++i) {
c.remove_random_server(0, 0);
c.remove_random_server(0, 1);
}
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;
}