context切换测试——线程创建有关部分请求review
线程模式开销
使用t_thread程序,循环1M次,重复6次,原始数据如下:
9.57,8.22,21098,0,0,0,104%
9.77,8.40,29704,0,0,0,104%
9.36,8.17,10390,0,0,0,106%
9.56,8.50,14514,0,0,0,107%
9.35,8.34,7244,0,0,0,108%
9.57,8.43,26351,0,0,0,106%
统计结果如下:
- time mean = 9.53
- time var = 0.02
- kernel mean = 8.34
- kernel var = 0.013
解读数据可以看到,thread模式的开销为9530ns(已经降到纳秒级了),CPU将为8340ns,精确级别在20ns级别。粗略换算一下每次create的开销大约是30k个时钟周期。简单对比可以看出,thread模式比fork模式大约快了5倍。