首页 > 编程语言 >c/c++获取uuid

c/c++获取uuid

时间:2023-10-01 22:44:22浏览次数:35  
标签:00 uuid libuuid c++ 获取 https boost

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

相关文章

  • C++中mutable关键字学习
    转自:https://liam.page/2017/05/25/the-mutable-keyword-in-Cxx/,讲的很好。1.介绍mutable即可变的,mutable只能用来修饰类的数据成员;而被mutable修饰的数据成员,可以在const成员函数中修改。例子:classHashTable{public://...std::stringlookup(conststd::......
  • NO.6 Linux 获取文件属性
    1/*2用于获取文件的属性和元数据信息,并输出到终端。3程序接受一个参数作为路径名,通过lstat函数获取指定文件的属性信息,并使用printf函数输出到终端。4注释对代码进行了简要解释,帮助理解各个部分的功能。5*/6#include<sys/types.h>7#include<sys/stat.h>8......
  • 在VS Code中配置C/C++
    之前因为学了一点html,所以下了一个VSCode来写html代码。今天要写C++的代码,以前都是用VS写的。但是突然想了一下既然都装了VSCode,为啥不配置一下。配置好了后以后写C/C++代码也不用打开繁重的VS了。而且VSCode还能加很多插件。说干就干,上网找了资料,终于配置好了。还是有蛮多坑......
  • C++常见算法&数据结构模版
    各种常见算法&数据结构模板1.最长不下降子序列(LIS)1.1\(O(n^2)\)做法点击查看代码for(inti=1;i<=n;i++){ cin>>a[i]; dp[i]=1; } for(inti=1;i<=n;i++){ for(intj=1;j<i;j++){ if(a[i]>a[j]){ dp[i]=max(dp[i],dp[j]+......
  • 视频监控/安防监控EasyCVR平台如何调取登录接口获取token?
    安防视频监控平台EasyCVR是一个具有强大拓展性、灵活的视频能力和轻便部署的平台。它支持多种主流标准协议,包括国标GB28181、RTSP/Onvif、RTMP等,还可以支持厂家的私有协议和SDK接入,例如海康Ehome、海大宇等设备的SDK。该平台不仅拥有传统安防视频监控的功能,还具备接入AI智能分析的......
  • C++ STL标准容器的特点和典型的使用场景
    概念和作用C++标准模板库(StandardTemplateLibrary,STL)提供了一组通用的模板类和函数,用于处理常见的数据结构和算法。STL中的标准容器是其中的重要组成部分,它们提供了不同的数据结构和操作方式,适用于各种不同的使用场景。说白了,就是每一种容器代表一种特定的数据结构。我们在学C......
  • AssetDatabase.LoadAssetAtPath 获取FBX资源空指针问题
    问题一 LoadAssetAtPath返回空publicclassProcessModel:AssetPostprocessor{privatevoidOnPostprocessModel(GameObjectinput){if(input.name!="Enemy2b")return;//取得导入模型相关信息ModelImporterimporter=ass......
  • C++对拍模版
    Windowscheck.cpp#include<bits/stdc++.h>usingnamespacestd;intmain(){ while(true) { system("data.exe"); system("std.exe"); system("brute.exe"); if(system("fcstd.outbrute.out"))......
  • C++快读、快写模版
    inlineintread(){ charch=getchar(); intx=0,f=1; while(!isdigit(ch))if(ch=='-')f=-1,ch=getchar(); while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); returnx*f;}inlinevoidprint(intn){if......
  • python 获取城市所属省份
    获取城市所属省份defgetProvince(cityValue):area_data={'北京':['北京市','朝阳区','海淀区','通州区','房山区','丰台区','昌平区','大兴区','顺义区','西城区','延......