moon_aka_sun (
moon_aka_sun) wrote2009-12-27 03:36 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Entry tags:
Python vs Javascript
Desktop, Athlon 64 X2 2.3GHz:
js/firefox 0.03 seconds c/gcc 0.07 js/chrome 0.33 py2+psycho 0.35 py3 2.59 js/opera 2.78 js cscript 3.06 py2 3.23 perl 3.36 js/ie8 4+ ruby 7.77 rebol 7.89Netbook, Atom n270 1.6GHz:
js/chrome 0.73 (2.2x) js cscript 5.34 (1.7x) py3 5.42 (2.1x)I just wanted to compare two langs and two comps. The program calculates Mandelbrot figure.
try: import psyco psyco.full() except ImportError: pass import sys, time BAILOUT = 16 MAX_ITERATIONS = 1000 def test(): out = '' for y in range(-39, 39): out += '\n' for x in range(-39, 39): i = mandelbrot(x/40.0, y/40.0) if i == 0: out += '*' else: out += ' ' print(out) def mandelbrot(x, y): cr = y - 0.5 ci = x zi = 0.0 zr = 0.0 i = 0 while True: i += 1 temp = zr * zi zr2 = zr * zr zi2 = zi * zi zr = zr2 - zi2 + cr zi = temp + temp + ci if zi2 + zr2 > BAILOUT: return i if i > MAX_ITERATIONS: return 0 t = time.time() test() print('\nPython Elapsed %.02f' % (time.time() - t))