MegaEntry - Social networking and discussion site!
我之前在某人的博客中看到一篇文章,他比较了很多语言的运行速度,包括Ruby、Io、 PHP、Python、Lua、Java、Perl、Applescript、TCL、ELispe、Javascript、OCaml、Ghostscript和C等。数据如下:|
语言 |
时间 |
相对速度 |
|
ocaml compiled 3.09.2 |
0.05 seconds |
1.00 x |
|
SBCL 1.0.2 |
0.13 seconds |
2.43 x |
|
C gcc-4.0.1 |
0.14 seconds |
2.67 x |
|
Java 1.4.2 |
0.39 seconds |
7.49 x |
|
Lua 5.1 |
1.25 seconds |
23.81 x |
|
Io 20070410 Vector |
1.37 seconds |
26.13 x |
|
ocaml bytecode 3.09.2 |
3.75 seconds |
71.48 x |
|
Python 2.5.1 |
9.99 seconds |
190.33 x |
|
Ghostscript 8.51 |
11.79 seconds |
224.51 x |
|
Perl 5.8.6 Optimized |
12.37 seconds |
235.57 x |
|
TCL 8.4 Optimized |
16.00 seconds |
304.76 x |
|
Perl 5.8.6 |
21.75 seconds |
414.29 x |
|
PHP 5.1.4 |
23.10 seconds |
440.05 x |
|
Javascript SpiderMonkey v1.6 |
31.14 seconds |
593.10 x |
|
Ruby 1.8.4 |
33.05 seconds |
629.54 x |
|
Emacs Lisp |
47.00 seconds |
895.24 x |
|
Applescript |
71.75 seconds |
1366.67 x |
|
Io 20070410 |
85.44 seconds |
1627.47 x |
|
import java.util.*; class Mandelbrot private static int iterate(float x, float y){float cr = y-0.5f;float ci = x;float zi = 0.0f;float zr = 0.0f; public static void run2(){int x,y; public static void run() {Date d1 = new Date();for (int i = 0; i < 100; i ) run2();Date d2 = new Date();long diff = d2.getTime() - d1.getTime();System.out.println("\nJava Elapsed " diff/1000.0f);} public static void main(String args[]) { |
|
#include MegaEntry - Social networking and discussion site! int mandelbrot(float x, float y){float cr = y - 0.5;float ci = x;float zi = 0.0;float zr = 0.0;int i = 0;while(1) {MegaEntry - Social networking and discussion site! i ;float temp = zr * zi;float zr2 = zr * zr;float zi2 = zi * zi;zr = zr2 - zi2 cr;zi = temp temp ci;if (zi2 zr2 > BAILOUT)return i;CopyRight owned by the original author.--(www.MegaEntry.com) if (i > MAX_ITERATIONS)return 0;} } void run2() {int x,y;for (y = -39; y < 39; y ) {fputs("\n", stderr);for (x = -39; x < 39; x ) {MegaEntry - Social networking and discussion site! int i = mandelbrot(x/40.0, y/40.0);if (i==0)fputs("*", stderr);elsefputs(" ", stderr);} }fputs("\n", stderr);MegaEntry - Social networking and discussion site! } void run() {struct timeval aTv;gettimeofday(&aTv, NULL);long init_time = aTv.tv_sec;long init_usec = aTv.tv_usec;int i;for (i = 0; i < 100; i )MegaEntry - Social networking and discussion site! run2();gettimeofday(&aTv,NULL);double query_time = (aTv.tv_sec - init_time) (double)(aTv.tv_usec - init_usec)/1000000.0; printf ("C Elapsed %0.2f\n", query_time);} int main (int argc, const char * argv[]) {run();run();MegaEntry - Social networking and discussion site! run();} |
$ java -cp rhino1_6R5/js.jar -server -XX:CompileThreshold=1 org.mozilla.javascript.tools.shell.Main -O 9 mandelbrot.js 2>/dev/nullJavaScript Elapsed 21.95JavaScript Elapsed 17.039JavaScript Elapsed 17.466JavaScript Elapsed 17.147 |
|