[pypy-issue] [issue1170] pi.py run too slow

zzz654321 tracker at bugs.pypy.org
Tue Jun 12 08:59:58 CEST 2012


New submission from zzz654321 <lightdarkadmin at 163.com>:

cmd line:
pypy pi.py 4000 > pi.txt

python 2.4 + psyco 7.0 sec
python 2.7 + psyco 4.7 sec
pypy 1.9 (1.8) 14.3 sec 

I don't known be at the bottom of the problem .

----------
files: pi.py
messages: 4422
nosy: pypy-issue, zzz654321
priority: performance bug
status: unread
title: pi.py run too slow

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1170>
________________________________________
-------------- next part --------------
#! /usr/bin/env python 
# -*- coding: cp936 -*- 

import sys, time 

def f(q, r, t, k ): 
	n= (3* q+ r )/ t 
	if (4* q+ r )/ t== n: 
		return (10* q, 
				10* (r- n* t ), 
				t, 
				k, 
				n ) 
	else: 
		return (q* k, 
				q* (4* k+ 2 )+ r* (2* k+ 1 ), 
				t* (2* k+ 1 ), 
				k+ 1 ) 

def pi(n = -1): 
	'¼ÆËã PI, ÀûÓÃÁËÎÞÏÞ¾«¶ÈµÄÕûÊýÕâ¸öÌØÐÔ' 
	out = '' 
	if(0>= n ): 
		n= 100 
	n= n+ 1 
	r = f(1, 0, 1, 1 ) 
	while(n ): 
		if(len(r )== 5 ): 
			out= out+ str(r[4 ] ) 
			n= n- 1 
		r= f(r[0 ], r[0x01 ], r[0x02 ], r[0x03 ] ) 
	out= out[0 ]+ '.'+ out[1: ] 
	return out 

class a1: 
	aaa= 0 
	
	def __init__(self ): 
		self.bbb= () 
	def f1(self ): 
		print "[", self.aaa, "]" 
	
class b1(a1 ): 
	
	def __init__(self ): 
		a1.__init__(self ) 
		print self.aaa, self.bbb 
	def f2(self ): 
		print "[", self.bbb, "]" 

try: 
	#import psyco 
	psyco.bind(f ) 
	psyco.bind(pi ) 
except: pass 

if __name__== '__main__': 
	t01= time.time() 
	n= 2000 
	if(2<= len(sys.argv ) ): 
		n= int(sys.argv[1 ] ) 
	print pi(n ) 
	print time.time()- t01 
	#a2= b1() 
	#a2.f1() 



More information about the pypy-issue mailing list