#### Topic: PyPy vs CPython, my benchmark

Full NumPy support is not implemented for PyPy yet, but some simple benchmarks could be performed.

To check performance PyPy vs CPython on a simple optimization problem I have extracted some code from my NLP goldenSection solver:

``````from numpy import *

def goldenSection(f, a, b, xtol):
a, b = min((a, b)), max((a, b))
s1 = 0.3819660112501051# (3-sqrt(double(5)))/2
s2 = 0.6180339887498949# (sqrt(double(5))-1)/2
x1 = a+s1*(b-a)
x2 = a+s2*(b-a)
y1,  y2 = f(x1),  f(x2)
for i in range(10000):
if y1 <= y2:
xmin,  ymin = x1,  y1
b,  x2 = x2,  x1
x1 = a + s1*(b - a)
y2, y1 = y1,  f(x1)
else:
xmin,  ymin = x2,  y2
a,  x1 = x1,  x2
x2 = a + s2*(b - a)
y1, y2 = y2,  f(x2)
# iterfcn()
if not i % 10: print('iter: %d   Diff_x: %e' %(i, b-a))
if b - a < xtol:
return xmin,  ymin, i
return xmin,  ymin, -1 # -1 means solution hasn't been reached

if __name__ == '__main__':
N = 10000
# 1
f = lambda x: sum([1e-20 * x**2 + x + (1e-20*x)**4 for i in range(N)])
# 2
f = lambda x: sum([sin(1e-20 * x) for i in range(N)])
# 3
f = lambda x: sum([abs(arctan(x)) for i in range(N)])

lb = -1e10
ub = 1e10
xtol = 1e-20
from time import time
t = time()
x_opt, f_opt, iter = goldenSection(f, lb, ub, xtol)
if iter == -1: print('solution has not been reached')
print('iter: %d   time elapsed: %0.1f' % (iter, time()-t))``````

Here's my output for those functions f, cases 1, 2, 3 in the code above:
PyPy 1.6                                       CPython 2.7.1+                    PyPy speedup, times
Case 1    iter: 78   time elapsed: 0.6                  iter: 78   time elapsed: 1.0                     1.7
Case 2    iter: 78   time elapsed: 0.4                  iter: 78   time elapsed: 3.7                     9.3
Case 3    iter: 142  time elapsed: 0.6                iter: 142  time elapsed: 7.1                    11.8

My arch: Linux KUBUNTU 11.04, AMD 3800+