首页  

java 和 C 循环和递归性能比较     所属分类 c 浏览量 633
LoopAndRecursionPerf.java 
loop-recursion-perf.c


不加编译优化选项
gcc loop-recursion-perf.c 

Java版本比c 快10倍 ( jvm 做了编译优化 ?)

加编译器优化
gcc -O1 loop-recursion-perf.c 
c版本秒杀Java 

优化之后 , 感觉像是把结果缓存起来了

完整代码

https://gitee.com/dyyx/hellocode/blob/master/src/LoopAndRecursionPerf.java   
https://gitee.com/dyyx/hellocode/blob/master/web/tech/c/demo/loop-recursion-perf.c




java版本运行结果 5050 5050 num=100,loopCount=10000000,outLoopCount=10 sum_test 331000,5050 318000,5050 297000,5050 301000,5050 296000,5050 298000,5050 296000,5050 296000,5050 297000,5050 297000,5050 sum_recursion_test 1320000,5050 1404000,5050 1428000,5050 1458000,5050 1393000,5050 1382000,5050 1388000,5050 1368000,5050 1401000,5050 1425000,5050
c 未加编译优化选项 版本 gcc loop-recursion-perf.c 5050 5050 num=100,loopCount=10000000,outLoopCount=10 sum_test 2826022,5050 2672223,5050 2651320,5050 2676550,5050 2644865,5050 2622577,5050 2605713,5050 2617831,5050 2650958,5050 2637007,5050 sum_recursion_test 4501735,5050 4597598,5050 4629046,5050 4474304,5050 4551706,5050 4906823,5050 6602356,5050 4553710,5050 4766816,5050 4526677,5050
c 编译优化版本 gcc -O1 loop-recursion-perf.c 5050 5050 num=100,loopCount=10000000,outLoopCount=10 sum_test 0,5050 0,5050 0,5050 0,5050 0,5050 0,5050 0,5050 0,5050 0,5050 1,5050 sum_recursion_test 1,5050 0,5050 1,5050 1,5050 1,5050 0,5050 0,5050 1,5050 1,5050 1,5050

上一篇     下一篇
Linux可执行文件信息查看

C语言获取时间戳秒

C语言获取时间戳秒毫秒微秒

C++11 chrono 获取时间戳

C语言字符串转浮点数

C语言排序和搜索