• C++ uuid_generate time cost


    //Util.h
    #ifndef Util_H
    #define Util_H #include <functional> #include <iostream> #include <mysql/mysql.h> #include <random> #include <sstream> #include <string.h> #include <thread> #include <uuid/uuid.h> #include <vector> #include "Model/Geeks.h" #include "Model/Parent.h" #include "Model/BookStruct.cpp" class Util { public: static char *uuidValue; static char *dtValue; void testTimeUuid(int loops); char *getUuid(); void printTimeCost13(chrono::time_point<chrono::system_clock> startTime, chrono::time_point<chrono::system_clock> endTime); }; #endif

    //Util.cpp
    
    #include "Model/Util.h"
    
    char *Util::uuidValue = (char *)malloc(40);
    char *Util::dtValue = (char *)malloc(20);
    
    void Util::testTimeUuid(int loops)
    {
        int interval=1000000;
        chrono::time_point<chrono::system_clock> startTime;
        chrono::time_point<chrono::system_clock> endTime;
        for(int i=0;i<loops;i++)
        {
            startTime=chrono::system_clock::now();
            for(int j=0;j<interval;j++)
            {
                getUuid();
            }
            endTime=chrono::system_clock::now();
            cout<<"Loop="<<i<<endl;
            printTimeCost13(startTime,endTime);
        }
    }
    
    char *Util::getUuid()
    {
        uuid_t newUUID;
        uuid_generate(newUUID);
        uuid_unparse(newUUID, uuidValue);
        return uuidValue;
    }
    
    void Util::printTimeCost13(chrono::time_point<chrono::system_clock> startTime,
                               chrono::time_point<chrono::system_clock> endTime)
    { 
        cout <<"Time cost:"
             << chrono::duration_cast<chrono::seconds>(endTime - startTime).count() << " seconds,"
             << chrono::duration_cast<chrono::milliseconds>(endTime - startTime).count() << " milliseconds,"
             << chrono::duration_cast<chrono::microseconds>(endTime - startTime).count() << " milliseconds,"
             << chrono::duration_cast<chrono::nanoseconds>(endTime - startTime).count() << " nanoseconds!!!"
             << endl;
    }
    //h1.cpp
    
    #include "Model/Util.h"
    
    void uuidTest13(int loops);
    
    int main(int args,char **argv)
    {
        try
        {
            uuidTest13(atoi(argv[1]));
        }
        catch(const std::exception& e)
        {
            std::cerr << e.what() << '\n';
        } 
    } 
    
    void uuidTest13(int loops)
    {
        Util ul;
        ul.testTimeUuid(loops);
    }

    Complile:

    g++ -g -std=c++2a -I. *.cpp ./Model/*.cpp -o h1 -lmysqlclient -luuid -lpthread;

    Execute in Win10+VMWare WorkStation Pro+Ubuntu+g++

  • 相关阅读:
    一款可以下拉搜索html下拉框控件
    Springboot+JPA+Thymeleaf 校园博客完整小网站
    OAuth 2.0 认证的原理与实践
    BootStrap 专题
    Rest接口和Thymeleaf的两个坑
    Android属性动画PropertyAnimation LayoutTransition(布局容器动画)
    Android 5.0中使用JobScheduler
    遍历Map的四种方法
    Android Error:(1,N1) 错误: 需要class, interface或enum
    Android.app.SuperNotCalledException错误
  • 原文地址:https://www.cnblogs.com/Fred1987/p/16304175.html
Copyright © 2020-2023  润新知