diff --git a/benchmarking.cpp b/benchmarking.cpp index 0fd08db..ffe91df 100644 --- a/benchmarking.cpp +++ b/benchmarking.cpp @@ -1,3 +1,65 @@ +#include +#include +#include +#include +#include +#include +#include "bank.h" + +#include +#include +#include +#include + +using namespace std::chrono; + +static Bank bank; + +#include +#include +#include + +#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((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((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 distribution(0.0, 1.0); + // std::default_random_engine generator; + // std::uniform_real_distribution 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; -} +} \ No newline at end of file