2018-08-09 21:02:20 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <random>
|
|
|
|
#include <chrono>
|
|
|
|
|
2018-08-18 01:39:26 +08:00
|
|
|
#include "uuid_v4.h"
|
2018-08-09 21:02:20 +08:00
|
|
|
|
2018-08-18 01:39:26 +08:00
|
|
|
#define IT 1000000000
|
2018-08-09 21:02:20 +08:00
|
|
|
|
2021-12-17 21:36:49 +08:00
|
|
|
void debugUUID(const UUIDv4::UUID &uuid) {
|
2018-08-18 01:39:26 +08:00
|
|
|
std::string bytes = uuid.bytes();
|
|
|
|
for (int i=0; i<16; i++) {
|
|
|
|
printf("%02hhx", bytes[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2018-08-09 21:02:20 +08:00
|
|
|
|
2022-07-18 18:06:13 +08:00
|
|
|
int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) {
|
2021-12-17 21:36:49 +08:00
|
|
|
UUIDv4::UUIDGenerator<std::mt19937_64> uuidGenerator;
|
2018-08-18 01:39:26 +08:00
|
|
|
char txt[37];
|
2018-08-09 21:02:20 +08:00
|
|
|
auto t1 = std::chrono::high_resolution_clock::now();
|
2018-08-18 01:39:26 +08:00
|
|
|
for (int i=0; i<IT; i++) {
|
2021-12-17 21:36:49 +08:00
|
|
|
UUIDv4::UUID test = uuidGenerator.getUUID();
|
2018-08-18 01:39:26 +08:00
|
|
|
test.str(txt);
|
2018-08-09 21:02:20 +08:00
|
|
|
}
|
|
|
|
auto t2 = std::chrono::high_resolution_clock::now();
|
|
|
|
auto diff = t2-t1;
|
2018-08-18 01:39:26 +08:00
|
|
|
std::cout << "ops/sec: " << IT / (std::chrono::duration_cast<std::chrono::nanoseconds>(diff).count() / 1e9) << std::endl;
|
2018-08-09 21:02:20 +08:00
|
|
|
|
2021-12-17 21:36:49 +08:00
|
|
|
UUIDv4::UUID load;
|
2018-08-18 17:16:17 +08:00
|
|
|
std::cin >> load;
|
|
|
|
std::cout << load << std::endl;
|
2018-08-09 21:02:20 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|