Thank you guys for your interest, I tried two things 1) put code into a function 2) use psyco.
1) by putting them into a function, there is a significant improvement, around 30% the running time will be around 0.3sec 2) by using psyco, it really does a great job, the running time is around 0.045sec. While trying this another question comes up, psyco seems to be able to optimize built-in functions & user's code, if I call a function from an external library, it seems doesn't help. A simple thing is I placed a = numpy.sin(a) in the loop rather than a = a+1, in this case, psyco doesn't have any improvement(or very little). if I put a = math.sin(a) which is from an built-in function, it can achieve a improvement around 3~4. Could the reason be that numpy.sin is actually calling a C library ? Actually Python does show comparable/better performance than other scripting languages. but I'm just surprised that matlab does a great job compared to python/perl, since matlab is also a interpreted language, I'm expecting it has silimar performance with python. I did some search, in previous discussion, people has compared python/numpy vs matlab, but it is actually comparison between numpy(which is implemented in c) vs matlab. Chao. import psyco #psyco.bind(functest) psyco.full() import numpy import time,math def functest(a): array = xrange(1000) for i in array: for j in array: a = a + 1 tic = time.time() a = 1.0 functest(a) toc = time.time() print toc-tic,' has elapsed' [EMAIL PROTECTED] wrote: > Chao, you can also try Psyco, applied on functions, and when necessary > using its metaclass too. > > Bye, > bearophile -- http://mail.python.org/mailman/listinfo/python-list