## [Jython-users] Why eval function in Jython is so slow?

 [Jython-users] Why eval function in Jython is so slow? From: FAN - 2005-09-23 15:55:27 ```hi, all I wrote a script to test eval function both in Jython and Python, I found eval function in Jython 2.1 is 10 times slower than Python 2.2 and 20 times slower than Python2.4. I think there must be some way to optimise it. Here's my testing script: #################################### import time class StopWatch: def __init__(self): =09self.startTime=3D-1 =09self.stopTime=3D-1 =09 def start(self): =09self.startTime =3D time.time() def stop(self): =09self.stopTime =3D time.time() def reset(self): =09self.startTime=3D-1 =09self.stopTime=3D-1 def gettime(self): =09if self.startTime =3D=3D -1: =09 raise "Watch not start yet!" =09if self.stopTime =3D=3D -1: =09 return time.time() - self.startTime =09else: =09 return self.stopTime - self.startTime def doEval(val): if (val >100 and val <=3D1000) or (val >1300 and val <=3D2000) or (val >2300 and val <=3D3000) or (val >3300 and val <=3D4000) or (val >4300 and val <=3D5000) or (val >5300 and val <=3D6000) or (val >6300 and val <=3D7000) or (val >7300 and val <=3D8000) or (val >8300 and val <=3D9000) o= r (val >9300 and val <=3D10000) : =09return 1 else: =09return 0 watch =3D StopWatch() watch.start() for i in range(10000): eval("doEval("+str(i)+")") print "Test eval of function 10000 times, spends: [", watch.gettime(), "] seconds" #################################### Result is: D:\Work\Jython>c:\python22\python eval_perf.py Test eval of function 10000 times, spends: [ 0.509999990463 ] seconds D:\Work\Jython>jython eval_perf.py Test eval of function 10000 times, spends: [ 10.805999994277954 ] seconds D:\Work\Jython>c:\python24\python eval_perf.py Test eval of function 10000 times, spends: [ 0.239999771118 ] seconds Regards -FAN ```

 [Jython-users] Why eval function in Jython is so slow? From: FAN - 2005-09-23 15:55:27 ```hi, all I wrote a script to test eval function both in Jython and Python, I found eval function in Jython 2.1 is 10 times slower than Python 2.2 and 20 times slower than Python2.4. I think there must be some way to optimise it. Here's my testing script: #################################### import time class StopWatch: def __init__(self): =09self.startTime=3D-1 =09self.stopTime=3D-1 =09 def start(self): =09self.startTime =3D time.time() def stop(self): =09self.stopTime =3D time.time() def reset(self): =09self.startTime=3D-1 =09self.stopTime=3D-1 def gettime(self): =09if self.startTime =3D=3D -1: =09 raise "Watch not start yet!" =09if self.stopTime =3D=3D -1: =09 return time.time() - self.startTime =09else: =09 return self.stopTime - self.startTime def doEval(val): if (val >100 and val <=3D1000) or (val >1300 and val <=3D2000) or (val >2300 and val <=3D3000) or (val >3300 and val <=3D4000) or (val >4300 and val <=3D5000) or (val >5300 and val <=3D6000) or (val >6300 and val <=3D7000) or (val >7300 and val <=3D8000) or (val >8300 and val <=3D9000) o= r (val >9300 and val <=3D10000) : =09return 1 else: =09return 0 watch =3D StopWatch() watch.start() for i in range(10000): eval("doEval("+str(i)+")") print "Test eval of function 10000 times, spends: [", watch.gettime(), "] seconds" #################################### Result is: D:\Work\Jython>c:\python22\python eval_perf.py Test eval of function 10000 times, spends: [ 0.509999990463 ] seconds D:\Work\Jython>jython eval_perf.py Test eval of function 10000 times, spends: [ 10.805999994277954 ] seconds D:\Work\Jython>c:\python24\python eval_perf.py Test eval of function 10000 times, spends: [ 0.239999771118 ] seconds Regards -FAN ```
 Re: [Jython-users] Why eval function in Jython is so slow? From: Diez B. Roggisch - 2005-09-23 16:05:53 ```FAN wrote: > hi, all > I wrote a script to test eval function both in Jython and Python, I > found eval function in Jython 2.1 is 10 times slower than Python 2.2 > and 20 times slower than Python2.4. > I think there must be some way to optimise it. Because it is implemented on top of the java runtime, not the C-runtime as CPython is - and thus it's slower. Why do you bother? Diez ```