-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis_bench.cpp
57 lines (48 loc) · 1.15 KB
/
redis_bench.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
#include <benchmark/benchmark.h>
#include <chrono>
#include <ctime>
#include <iostream>
#include <thread>
#include "redis_manager.hpp"
using namespace std::chrono;
static RedisManager redisManager("VRSC_BENCH", "127.0.0.1:6379");
static void BM_GetCurTime(benchmark::State& state)
{
for (auto _ : state)
{
std::time_t time =
duration_cast<milliseconds>(system_clock::now().time_since_epoch())
.count();
}
}
static void BM_GetCurTimeC(benchmark::State& state)
{
for (auto _ : state)
{
struct timeval time_now
{
};
gettimeofday(&time_now, nullptr);
time_t msecs_time =
(time_now.tv_sec * 1000) + (time_now.tv_usec / 1000);
}
}
// create a timeseries for each worker
static void BM_AddWorker(benchmark::State& state)
{
for (auto _ : state)
{
redisManager.AddWorker("worker1");
}
}
static void BM_AddShare(benchmark::State& state)
{
for (auto _ : state)
{
redisManager.AddShare("worker1", 1647508482627, 15042.401234);
}
}
BENCHMARK(BM_GetCurTime);
BENCHMARK(BM_GetCurTimeC);
BENCHMARK(BM_AddWorker);
BENCHMARK(BM_AddShare);