c/c++标准库中没有自带的uuid工具函数/类,可以使用三方库libuuid,boost,或者手工实现,如下:
[zjh@hs-10-20-xxx lib]$ sudo yum install libuuid-devel [sudo] password for zjh: Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile base | 1.8 kB 00:00:00 extras | 1.4 kB 00:00:00 updates | 1.5 kB 00:00:00 Package libuuid-devel-2.23.2-65.el7_9.1.x86_64 already installed and latest version Nothing to do
测试程序
// boost版本异常慢 void test_uuid_perf() { // boost::uuids::uuid a_uuid; vector<string> myvertor; uuid_t uu; char uuid_str[37]; struct timeval start, stop, diff; gettimeofday(&start, 0); //开始计时 for (int i=0;i<100000;i++) { // a_uuid = boost::uuids::random_generator()(); // myvertor.emplace_back(boost::uuids::to_string(a_uuid)); uuid_generate(uu); uuid_unparse_lower(uu, uuid_str); string str1(uuid_str); myvertor.emplace_back(str1); } cout << myvertor[10] << endl; gettimeofday(&stop, 0); //结束计时 timeval_subtract(&diff, &start, &stop); printf("总计用时:%d秒%d微秒\n",diff.tv_sec, diff.tv_usec); // boost版本,10万个uuid 17秒多; uuid版本, 10万个0.5秒,35倍 printf("完成"); }
https://www.cnblogs.com/nanfei/p/11742249.html libuuid,性能最佳,是手工和boost的几十倍
https://www.jianshu.com/p/33639aee1ffa,https://blog.51cto.com/u_14508933/5565901 手工编写
https://blog.csdn.net/chiefarbiter/article/details/90201581 boost
标签:00,uuid,libuuid,c++,获取,https,boost From: https://www.cnblogs.com/lightdb/p/17738818.html