-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrandomread_test.cpp
49 lines (39 loc) · 1.15 KB
/
randomread_test.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
#define BOOST_TEST_MODULE randomread
#include <boost/test/included/unit_test.hpp>
#include <string>
#include <filesystem>
#include <chrono>
#include <random>
#include "database.h"
#include "./test_helpers.h"
static const int nr = 1000000;
static const int kSize = 16;
static const std::string dbname = "testdb/mydb";
static void _testReadRandom(DatabaseRef &db) {
std::vector<int> keys(nr);
for(int i=0;i<nr;i++) {
keys.push_back(i);
}
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(keys.begin(),keys.end(),g);
auto start = std::chrono::system_clock::now();
ByteBuffer value;
auto format = ("%0"+std::to_string(kSize)+"d");
for(int index : keys) {
char tmp[kSize+1];
snprintf(tmp,kSize+1,format.c_str(),index);
auto val = db->get(tmp,value);
}
auto end = std::chrono::system_clock::now();
auto ms = millis(end,start);
std::cout << "read random time " << (ms*1000)/(double)(nr) << " us per get\n";
}
static void _testRead() {
auto db = Database::open(dbname,Options());
_testReadRandom(db);
db->close();
}
BOOST_AUTO_TEST_CASE( randomread ) {
_testRead();
}