Menu

[r3313]: / trunk / py4science / book / examples / error.py  Maximize  Restore  History

Download this file

61 lines (48 with data), 1.2 kB

 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
"""
file with deliberate syntax errors to check IPython.
"""
g1='a global'
def f():
1/0
class foo:
"""foo class docstring"""
def __init__(self):
"""init ds"""
pass
class bar:
"""bar class docstring"""
def __init__(self):
"""bar init ds"""
pass
def __call__(self):
"""call ds"""
print 'bar called!'
from Numeric import *
import time,sys
def Ramp(result, size, start, end):
step = (end-start)/(size-1)
for i in xrange(size):
result[i] = start + step*i
def RampNum(result, size, start, end):
step = (end-start)/(size-1)
result[:] = arange(size+1)*step + start
def main():
#print 'hi'
size = 6000
reps = 10
array_normal = [0]*size
t0=time.clock()
for i in xrange(reps):
Ramp(array_normal, size, 0.0, 1.0)
Rtime = time.clock()-t0
#print 'Ramp time:', Rtime
t0=time.clock()
array_num = zeros(size,'d')
for i in xrange(reps):
RampNum(array_num, size, 0.0, 1.0)
RNtime = time.clock()-t0
print 'RampNum time:', RNtime
print 'speedup:',Rtime/RNtime
if __name__ == '__main__':
main()
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.