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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | #include < chrono > #include < iostream > #include < uuid /uuid.h> using namespace std; void uuid_generatenewUUID(int x); void uuid_generate_randomnewUUID(int x); void uuid_generate_timenewUUID(int x); void uuid_generate_timeSafenewUUID(int x); void testUuid_generate_timeSafe(int x); int main(int args,char**argv) { int x=atoi(argv[1]); uuid_generatenewUUID(x); uuid_generate_randomnewUUID(x); uuid_generate_timenewUUID(x); uuid_generate_timeSafenewUUID(x); // testUuid_generate_timeSafe(x); } void testUuid_generate_timeSafe(int x) { char* uuidValue=(char*)malloc(40); chrono::time_point< chrono::steady_clock > startTime; chrono::time_point< chrono::steady_clock > endTime; for(int i=0;i< x ;i++) { startTime = chrono ::steady_clock::now(); uuid_t newUUID; uuid_generate_time(newUUID); uuid_unparse(newUUID,uuidValue); endTime = chrono ::steady_clock::now(); cout<<i<<","<<uuidValue<<","<<chrono::duration_cast<chrono::nanoseconds>(endTime-startTime).count()<<" nanos!"<< endl ; } } void uuid_generate_timeSafenewUUID(int x) { cout<<"In uuid_generate_timeSafenewUUID!"<<endl; chrono::time_point<chrono::steady_clock> startTime; chrono::time_point< chrono::steady_clock > endTime; for(int i=0;i< x ;i++) { startTime = chrono ::steady_clock::now(); for(int j = 0 ;j<1000000;j++) { uuid_t newUUID; uuid_generate_time_safe(newUUID); } endTime = chrono ::steady_clock::now(); cout<<i<<","<<chrono::duration_cast<chrono::milliseconds>(endTime-startTime).count()<<" milliseconds!"<< endl ; } } void uuid_generate_timenewUUID(int x) { cout<<"In uuid_generate_timenewUUID!"<<endl; chrono::time_point<chrono::steady_clock> startTime; chrono::time_point< chrono::steady_clock > endTime; for(int i=0;i< x ;i++) { startTime = chrono ::steady_clock::now(); for(int j = 0 ;j<1000000;j++) { uuid_t newUUID; uuid_generate_time(newUUID); } endTime = chrono ::steady_clock::now(); cout<<i<<","<<chrono::duration_cast<chrono::milliseconds>(endTime-startTime).count()<<" milliseconds!"<< endl ; } } void uuid_generatenewUUID(int x) { cout<<"In uuid_generatenewUUID"<<endl; chrono::time_point<chrono::steady_clock> startTime; chrono::time_point< chrono::steady_clock > endTime; for(int i=0;i< x ;i++) { startTime = chrono ::steady_clock::now(); for(int j = 0 ;j<1000000;j++) { uuid_t newUUID; uuid_generate(newUUID); } endTime = chrono ::steady_clock::now(); cout<<i<<","<<chrono::duration_cast<chrono::milliseconds>(endTime-startTime).count()<<" milliseconds!"<< endl ; } } void uuid_generate_randomnewUUID(int x) { cout<<"In uuid_generate_randomnewUUID"<<endl; chrono::time_point<chrono::steady_clock> startTime; chrono::time_point< chrono::steady_clock > endTime; for(int i=0;i< x ;i++) { startTime = chrono ::steady_clock::now(); for(int j = 0 ;j<1000000;j++) { uuid_t newUUID; uuid_generate_random(newUUID); } endTime = chrono ::steady_clock::now(); cout<<i<<","<<chrono::duration_cast<chrono::milliseconds>(endTime-startTime).count()<<" milliseconds!"<<endl; } } |
Compile
1 | g++ -std=c++2a *.cpp -o h1 -luuid |
Run
1 | ./h1 10 |
Snapshot
Referenced https://www.man7.org/linux/man-pages/man3/uuid_generate.3.html#:~:text=The%20uuid_generate%20%28%29%20function%20creates%20a%20new%20universally,from%20getrandom%20%282%29%2C%20%2Fdev%2Furandom%2C%20or%20%2Fdev%2Frandom%20if%20available.