• Lua5.2 一些性能测评


    1. luaL_newstate测试

     1 #include<time.h>
     2 
     3 #include<iostream>
     4 using namespace std;
     5 
     6 #include<lua.hpp>
     7 
     8 int main()
     9 {
    10     clock_t  time_start = clock();
    11 
    12     for(int i =0;i<100000;++i)
    13     {
    14         lua_State *l = luaL_newstate();
    15     }
    16 
    17     clock_t  time_end = clock();
    18     printf("this time use %lfs\n", (double)(time_end - time_start)/CLOCKS_PER_SEC);
    19     system("pause");
    20     return 0;
    21 }

    运行结果:

    this time use 4.225000s

    一秒大约可以新建2W个空state

    2.测试newthread

    #include<time.h>
    
    #include<iostream>
    using namespace std;
    
    #include<lua.hpp>
    
    int main()
    {
        clock_t  time_start = clock();
    
        lua_State *master = luaL_newstate();
    
        for(int i =0;i<30;++i)
        {
            lua_State *l = lua_newthread(master);
        }
    
        clock_t  time_end = clock();
        printf("this time use %lfs\n", (double)(time_end - time_start)/CLOCKS_PER_SEC);
        system("pause");
        return 0;
    }

    运行结果:

    this time use 0.001000s

    state最好不要太多,堆栈容易爆掉。看来设计的时候叫thread意思就是当它是伪线程用

      

    除非注明,Cydonia博客文章均为原创,转载请以链接形式标明本文地址

      

    博客地址:http://www.cnblogs.com/cydonia/

  • 相关阅读:
    CentOS 阿里源
    使用分区挂载 ftp 目录
    Docker-compose常用命令
    docker 启动容器失败 id already in use
    Docker daemon.json 的配置项目合集
    Watchtower
    umount 时目标忙解决办法
    opencontrail 参考资料
    使用disk-image-builder(DIB)制作Ironic 裸金属镜像
    Nodejs常见安装
  • 原文地址:https://www.cnblogs.com/cydonia/p/2892067.html
Copyright © 2020-2023  润新知