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意思就是当它是伪线程用