$ cat erf.c #include< stdio.h> #include< math.h> 双倍erfc(双x) { 双倍p,a1,a2,a3,a4,a5; 双t ,erfcx; p = 0.3275911; a1 = 0.254829592; a2 = -0.284496736; a3 = 1.421413741; a4 = -1.453152027; a5 = 1.061405429; t = 1.0 /(1.0 + p * x); erfcx =((a1 +(a2 +(a3 + (a4 + a5 * t)* t)* t)* t)* t) * exp(-x * x); 返回erfcx; } int main() { double erg = 0.0; int i; for(i = 0; i< 1000000; i ++) { erg = erg + erfc(0.456); } 返回0; } Michele Simionato,博士。 Mi ************** @ libero.it http://www.phyast.pitt.edu/~micheles ---目前正在找工作---I posted this few weeks ago (remember the C Sharp thread?) but it wentunnoticed on the large mass of posts, so let me retry. Here I get Python+Psyco twice as fast as optimized C, so I would like to now if somethingis wrong on my old laptop and if anybody can reproduce my results.Here are I my numbers for calling the error function a million times(Python 2.3, Psyco 1.0, Red Hat Linux 7.3, Pentium II 366 MHz):$ time p23 erf.pyreal 0m0.614suser 0m0.551ssys 0m0.029sThis is twice as fast as optimized C:$ gcc erf.c -lm -o3$ time ./a.outreal 0m1.125suser 0m1.086ssys 0m0.006sHere is the situation for pure Python$time p23 erf.jyreal 0m25.761suser 0m25.012ssys 0m0.049sand, just for fun, here is Jython performance:$ time jython erf.jyreal 0m42.979suser 0m41.430ssys 0m0.361sThe source code follows (copied from Alex Martelli''s post):----------------------------------------------------------------------$ cat erf.pyimport mathimport psycopsyco.full()def erfc(x):exp = math.expp = 0.3275911a1 = 0.254829592a2 = -0.284496736a3 = 1.421413741a4 = -1.453152027a5 = 1.061405429t = 1.0 / (1.0 + p*x)erfcx = ( (a1 + (a2 + (a3 +(a4 + a5*t)*t)*t)*t)*t ) * exp(-x*x)return erfcxdef main():erg = 0.0for i in xrange(1000000):erg += erfc(0.456)if __name__ == ''__main__'':main()--------------------------------------------------------------------------# python/jython version = same without "import psyco; psyco.full()"--------------------------------------------------------------------------$cat erf.c#include <stdio.h>#include <math.h>double erfc( double x ){double p, a1, a2, a3, a4, a5;double t, erfcx;p = 0.3275911;a1 = 0.254829592;a2 = -0.284496736;a3 = 1.421413741;a4 = -1.453152027;a5 = 1.061405429;t = 1.0 / (1.0 + p*x);erfcx = ( (a1 + (a2 + (a3 +(a4 + a5*t)*t)*t)*t)*t ) * exp(-x*x);return erfcx;}int main(){double erg=0.0;int i;for(i=0; i<1000000; i++){erg = erg + erfc(0.456);}return 0;}Michele Simionato, Ph. D. Mi**************@libero.it http://www.phyast.pitt.edu/~micheles--- Currently looking for a job ---推荐答案时间p23 erf.py 实际0m0 .614s 用户0m0.551s sys 0m0.029s 这是优化C的两倍:time p23 erf.pyreal 0m0.614suser 0m0.551ssys 0m0.029sThis is twice as fast as optimized C: gcc erf.c -lm -o3gcc erf.c -lm -o3 time ./a.out real 0m1.125s 用户0m1.086s sys 0m0.006s 以下是纯Python的情况time ./a.outreal 0m1.125suser 0m1.086ssys 0m0.006sHere is the situation for pure Python 这篇关于Python速度很快(是:Python的速度有多快)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-29 05:46