-
Notifications
You must be signed in to change notification settings - Fork 0
/
micro.py3
71 lines (54 loc) · 1.58 KB
/
micro.py3
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
61
62
63
64
65
66
67
68
69
70
71
import time;
def f1():
start = float(time.clock())
x = 10
for i in range(100000):
x = ( 2 * x ) + x + 1;
# print "t1 answer %d time %f" % (x, float(time.clock()) - start)
print("f1 time %f seconds" % ( float(time.clock()) - start))
# Create nStrings strings.
# the first string just has the character 'a', the second one is 'ab', etc
# you end up with an array of strings, some short some long
def f2():
t0 = float(time.clock())
nStrings = 1000
nCats = 100000
a1 = []
c = ord('a')
a1.append( str(c) )
for i in range(1,nStrings):
c += 1
c = c % 256
if c == 0:
c += 1
a1.append ( a1[i-1] + str(c) )
t1 = float(time.clock())
a2 = []
for i in range(0,nCats):
a2.append( a1[i % len(a1)] + a1[(i+7)%len(a1)] + a1[(i+17)%len(a1)] + a1[(i+27)%len(a1)] + a1[(i+37)%len(a1)] + a1[(i+47)%len(a1)] + a1[(i+57)%len(a1)] )
t2 = float(time.clock())
a3 = []
for i in range(0,nCats):
a7 = []
a7.append( a1[i%len(a1)] )
a7.append( a1[(i+7)%len(a1)] )
a7.append( a1[(i+17)%len(a1)] )
a7.append( a1[(i+27)%len(a1)] )
a7.append( a1[(i+37)%len(a1)] )
a7.append( a1[(i+47)%len(a1)] )
a7.append( a1[(i+57)%len(a1)] )
a3.append ( "".join( a7 ) )
t3 = float(time.clock())
print("f2 createstr %f sec , plus cat %f sec, join %f sec" % ( t1 - t0, t2 - t1, t3 - t2))
def f5():
start = float(time.clock())
for x in range(1000000):
a = {}
for a1 in range(50):
a[a1] = str(a1)
print("f5 %f seconds" % (time.clock() - start))
print("quick performance test")
f1()
f2()
f5()
print("end quick performance test")