-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.cc
68 lines (55 loc) · 1.95 KB
/
bench.cc
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
#include <limits.h>
#include <stdint.h>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <boost/random.hpp>
#include <boost/timer.hpp>
#include "sl.hpp"
const int nodes = 2000000;
using namespace std;
using namespace boost;
typedef sl<int,int, 24> skip;
skip skiplist(INT_MIN, INT_MAX, 0);
template<typename rand>
void inserter(int i, rand& rnd, int seed){
while(seed-->0)rnd();
while(i>0){
skiplist.add(rnd(),1);
--i;
}
};
template<typename rand>
void deleter(int i, rand& rnd, int seed){
while(seed-->0)rnd();
while(i>0){
int random = rnd();
skiplist.remove(random);
// assert(!skiplist.contains(random));
--i;
}
};
int main(){
using namespace boost;
typedef variate_generator<mt19937&, uniform_int<> > random_type;
mt19937 gen1(1),gen2(2),gen3(3),gen4(4);
mt19937 gen5(1),gen6(2),gen7(3),gen8(4);
uniform_int<> dst(0, 100000000);
boost::timer t;
boost::thread ins1(boost::bind(&::inserter<random_type>, nodes/4, random_type(gen1, dst), 1));
boost::thread ins2(boost::bind(&::inserter<random_type>, nodes/4, random_type(gen2, dst), 2));
boost::thread ins3(boost::bind(&::inserter<random_type>, nodes/4, random_type(gen3, dst), 3));
boost::thread ins4(boost::bind(&::inserter<random_type>, nodes/4, random_type(gen4, dst), 4));
// usleep(1000000);
ins1.join();ins2.join();ins3.join();ins4.join();
boost::thread del1(boost::bind(&::deleter<random_type>, nodes/4, random_type(gen5, dst), 5));
boost::thread del2(boost::bind(&::deleter<random_type>, nodes/4, random_type(gen6, dst), 6));
boost::thread del3(boost::bind(&::deleter<random_type>, nodes/4, random_type(gen7, dst), 7));
boost::thread del4(boost::bind(&::deleter<random_type>, nodes/4, random_type(gen8, dst), 8));
// skiplist.dump();
del1.join();del2.join();del3.join();del4.join();
int time = t.elapsed();
if(time == 0) time++;
//date_time::subsecond_duration<time_duration, long long int>
std::cout << nodes/time << " ops" << std::endl;
}