Linux C++ generate via uuid_generate_time,uuid_generate_time_safe,uuid_generate,uuid_generate_random
2022/7/26 5:22:50
本文主要是介绍Linux C++ generate via uuid_generate_time,uuid_generate_time_safe,uuid_generate,uuid_generate_random,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#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
g++ -std=c++2a *.cpp -o h1 -luuid
Run
./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.
这篇关于Linux C++ generate via uuid_generate_time,uuid_generate_time_safe,uuid_generate,uuid_generate_random的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-12如何创建可引导的 ESXi USB 安装介质 (macOS, Linux, Windows)
- 2024-11-08linux的 vi编辑器中搜索关键字有哪些常用的命令和技巧?-icode9专业技术文章分享
- 2024-11-08在 Linux 的 vi 或 vim 编辑器中什么命令可以直接跳到文件的结尾?-icode9专业技术文章分享
- 2024-10-22原生鸿蒙操作系统HarmonyOS NEXT(HarmonyOS 5)正式发布
- 2024-10-18操作系统入门教程:新手必看的基本操作指南
- 2024-10-18初学者必看:操作系统入门全攻略
- 2024-10-17操作系统入门教程:轻松掌握操作系统基础知识
- 2024-09-11Linux部署Scrapy学习:入门级指南
- 2024-09-11Linux部署Scrapy:入门级指南
- 2024-08-21【Linux】分区向左扩容的方法