Menu

[r4655]: / trunk / py4science / examples / pyrex / sums_test.py  Maximize  Restore  History

Download this file

30 lines (23 with data), 537 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import numpy
import sums
def sumpy(arr):
total = 0.
for val in x:
total += val
return total
x = numpy.arange(10)
y = numpy.random.rand(10,10)
print 'sum(x)', sums.sum_elements(x)
print 'sum2(x)', sums.sum_elements2(x)
print 'sum(y)', sums.sum_elements(y)
#print 'sum2(y)', sums.sum_elements2(y)
x = numpy.arange(1e6)
import time
start = time.time()
s1 = sums.sum_elements2(x)
now = time.time()
print 'pyrex time', now - start
start = time.time()
s1 = sumpy(x)
now = time.time()
print 'python time', now - start
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.