fixed benchmark

This commit is contained in:
EntireTwix 2021-07-05 16:30:54 -07:00
parent a98a813189
commit 6bc6c78ed7

View file

@ -1,3 +1,65 @@
#include <iostream>
#include <chrono>
#include <thread>
#include <sys/types.h>
#include <unistd.h>
#include <random>
#include "bank.h"
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
using namespace std::chrono;
static Bank bank;
#include <ctime>
#include <ratio>
#include <chrono>
#define time_func_a(f, a, x) \
{ \
using namespace std::chrono; \
uint32_t timer = 0; \
for (int i = 0; i < x; ++i) \
{ \
auto t1 = high_resolution_clock::now().time_since_epoch(); \
f; \
auto t2 = high_resolution_clock::now().time_since_epoch(); \
a; \
timer += std::chrono::duration_cast<std::chrono::nanoseconds>((t2 - t1)).count(); \
} \
std::cout << timer / x << '\n'; \
}
#define time_func(f, x) \
{ \
using namespace std::chrono; \
uint32_t timer = 0; \
for (int i = 0; i < x; ++i) \
{ \
auto t1 = high_resolution_clock::now().time_since_epoch(); \
f; \
auto t2 = high_resolution_clock::now().time_since_epoch(); \
timer += std::chrono::duration_cast<std::chrono::nanoseconds>((t2 - t1)).count(); \
} \
std::cout << timer / x << '\n'; \
}
#define Op_a(v, name, x, a) \
{ \
std::cout << name; \
time_func_a(v, a, x); \
}
#define Op(v, name, x) \
{ \
std::cout << name; \
time_func(v, x); \
}
int main(int argc, char **argv)
{
bank.AddUser("twix", 0, "root");
@ -26,18 +88,18 @@ int main(int argc, char **argv)
#endif
//GetBal scalining test
std::default_random_engine generator;
std::uniform_real_distribution<double> distribution(0.0, 1.0);
// std::default_random_engine generator;
// std::uniform_real_distribution<double> distribution(0.0, 1.0);
for (size_t i = 0; i < 10000000; ++i)
{
bank.AddUser(std::to_string(i), 100000, "root");
if (i % 10000 == 0)
{
auto u = std::to_string((int)(distribution(generator) * i));
Op(bank.GetBal(u), std::to_string(i) + ", ", 100000);
}
}
// for (size_t i = 0; i < 10000000; ++i)
// {
// bank.AddUser(std::to_string(i), 100000, "root");
// if (i % 10000 == 0)
// {
// auto u = std::to_string((int)(distribution(generator) * i));
// Op(bank.GetBal(u), std::to_string(i) + ", ", 100000);
// }
// }
return 0;
}
}