Re: QBASIC 和 C 和 PYTHON 和 LUA 执行速度大比拼
发表于 : 2012-11-26 22:43
小学的时候小霸王上玩过。。。不懂是啥。。。
FPGA的硬件描述语言表示秒杀……估计dsp的汇编也秒杀……蔡万钊 写了:![]()
![]()
![]()
![]()
![]()
![]()
顶我的 QBASIC 语言~~~
大牛啊,我一直好想写个C编译器的蔡万钊 写了:![]()
![]()
![]()
![]()
![]()
![]()
顶我的 QBASIC 语言~~~
代码: 全选
/*jslint node:true */
function fib(n) {
"use strict";
if (n < 2) {
return n;
}
return fib(n - 2) + fib(n - 1);
}
console.log(fib(40));
代码: 全选
% make c
cc -Wall -Wextra -g -O2 c.c -o c
[Login] chenfengyuan at Fengyuans-MacBook-Air in /Users/chenfengyuan/tmp/test
% time node a.js
102334155
node a.js 1.79s user 0.02s system 100% cpu 1.794 total
[Login] chenfengyuan at Fengyuans-MacBook-Air in /Users/chenfengyuan/tmp/test
% time ./c
102334155
./c 0.83s user 0.00s system 99% cpu 0.832 total
代码: 全选
(declaim (optimize (speed 3) (debug 0) (space 0) (safety 0)))
(defun fib (n)
(case n
((0 1) n)
(t (+ (fib (- n 1)) (fib (- n 2))))))
代码: 全选
CL-USER> (time (format t "~a~%" (fib 40)))
102334155
(FORMAT T "~a~%" (FIB 40))
took 1,399,947 microseconds (1.399947 seconds) to run.
During that period, and with 4 available CPU cores,
1,399,866 microseconds (1.399866 seconds) were spent in user mode
452 microseconds (0.000452 seconds) were spent in system mode
432 bytes of memory allocated.
NIL
CL-USER>
硬件都不一样。没意义。ChenFengyuan 写了:代码: 全选
/*jslint node:true */ function fib(n) { "use strict"; if (n < 2) { return n; } return fib(n - 2) + fib(n - 1); } console.log(fib(40));
代码: 全选
% make c cc -Wall -Wextra -g -O2 c.c -o c [Login] chenfengyuan at Fengyuans-MacBook-Air in /Users/chenfengyuan/tmp/test % time node a.js 102334155 node a.js 1.79s user 0.02s system 100% cpu 1.794 total [Login] chenfengyuan at Fengyuans-MacBook-Air in /Users/chenfengyuan/tmp/test % time ./c 102334155 ./c 0.83s user 0.00s system 99% cpu 0.832 total
代码: 全选
(declaim (optimize (speed 3) (debug 0) (space 0) (safety 0))) (defun fib (n) (case n ((0 1) n) (t (+ (fib (- n 1)) (fib (- n 2))))))
没把js,cl秒掉。。代码: 全选
CL-USER> (time (format t "~a~%" (fib 40))) 102334155 (FORMAT T "~a~%" (FIB 40)) took 1,399,947 microseconds (1.399947 seconds) to run. During that period, and with 4 available CPU cores, 1,399,866 microseconds (1.399866 seconds) were spent in user mode 452 microseconds (0.000452 seconds) were spent in system mode 432 bytes of memory allocated. NIL CL-USER>
我不是跑了你的C么,和C比a阿蔡万钊 写了:硬件都不一样。没意义。ChenFengyuan 写了:代码: 全选
/*jslint node:true */ function fib(n) { "use strict"; if (n < 2) { return n; } return fib(n - 2) + fib(n - 1); } console.log(fib(40));
代码: 全选
% make c cc -Wall -Wextra -g -O2 c.c -o c [Login] chenfengyuan at Fengyuans-MacBook-Air in /Users/chenfengyuan/tmp/test % time node a.js 102334155 node a.js 1.79s user 0.02s system 100% cpu 1.794 total [Login] chenfengyuan at Fengyuans-MacBook-Air in /Users/chenfengyuan/tmp/test % time ./c 102334155 ./c 0.83s user 0.00s system 99% cpu 0.832 total
代码: 全选
(declaim (optimize (speed 3) (debug 0) (space 0) (safety 0))) (defun fib (n) (case n ((0 1) n) (t (+ (fib (- n 1)) (fib (- n 2))))))
没把js,cl秒掉。。代码: 全选
CL-USER> (time (format t "~a~%" (fib 40))) 102334155 (FORMAT T "~a~%" (FIB 40)) took 1,399,947 microseconds (1.399947 seconds) to run. During that period, and with 4 available CPU cores, 1,399,866 microseconds (1.399866 seconds) were spent in user mode 452 microseconds (0.000452 seconds) were spent in system mode 432 bytes of memory allocated. NIL CL-USER>
windows 下安装 python 费事呢!ChenFengyuan 写了:我的机器想跑个qbasic都得弄一段时间,如何秒基本全平台都有的py?
![]()
![]()
你可以来贴代码阿yjcong 写了:为什么没人试试forth呢?
高屋建瓴啊……eexpress 写了:都傻了,比一段代码。那种语言都可以挑出一段比其他语言有优势的代码。而且,速度不是语言的全部,编写方便是语言的另外一个支点。
上升点层次吧。其实,个人技巧,才是最重要的。
硬要比速度,等你们的代码能在12M的cpu上跑。再比吧。那时候,速度的差异放大无数倍了。lol