-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_single.cpp
67 lines (57 loc) · 1.95 KB
/
test_single.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
#define BENCHMARK
#include <iostream>
#include <fstream>
#include <ctime>
#include <vector>
#include <algorithm>
#include "../lib/database.hpp"
#include "../lib/utility.hpp"
#include "../lib/optional.hpp"
#include "data_seeder.h"
const int SAMPLE_NUM = 1 << 7;
const int SAMPLE_SIZE = 1 << 13;
double res[200][3];
enum TestType {INSERT, SEARCH, DELETE};
int main()
{
DataSeeder seeder((SAMPLE_NUM + 1) * SAMPLE_SIZE);
laindb::Database<int> db("test", laindb::NEW);
for (int i = 0; i < SAMPLE_NUM; ++i){
//step 1
for (int j = i * SAMPLE_SIZE; j < (i + 1) * SAMPLE_SIZE; ++j){
db.put(seeder.key_for_put().c_str(), j);
}
//step 2 - insert
int begin = db.TIME;
for (int j = (i + 1) * SAMPLE_SIZE; j < (i + 2) * SAMPLE_SIZE; ++j){
db.put(seeder.key_for_put().c_str(), j);
}
int end = db.TIME;
res[i][INSERT] = (end - begin) / static_cast<double>(CLOCKS_PER_SEC) * 1000;
//step 3 - search
begin = db.TIME;
for (int j = (i + 1) * SAMPLE_SIZE; j < (i + 2) * SAMPLE_SIZE; ++j){
laindb::Optional<int> t = db.get(seeder.key_for_get().c_str());
}
end = db.TIME;
res[i][SEARCH] = (end - begin) / static_cast<double>(CLOCKS_PER_SEC) * 1000;
//step 4 - delete
begin = db.TIME;
for (int j = (i + 1) * SAMPLE_SIZE; j < (i + 2) * SAMPLE_SIZE; ++j){
db.erase(seeder.key_for_del().c_str());
}
end = db.TIME;
res[i][DELETE] = (end - begin) / static_cast<double>(CLOCKS_PER_SEC) * 1000;
}
std::ofstream fout("res.js");
fout << "var res=[";
for (int i = 0; i < SAMPLE_NUM; ++i){
fout << '[' << (i + 1) * SAMPLE_SIZE << ',' << res[i][INSERT] << ',' << res[i][SEARCH] << ',' << res[i][DELETE] << ']';
if (i < SAMPLE_NUM - 1){
fout << ',' << std::endl;
}else{
fout << "];" << std::endl;
}
}
return 0;
}