forked from majek/dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
python-list-vs-tuple.py
75 lines (58 loc) · 1.45 KB
/
python-list-vs-tuple.py
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
72
73
74
import time
def do_tuple(no):
for i in xrange(no):
xx = (1,2,3,4,5,6,7,8,9)
def do_list(no):
for i in xrange(no):
xx = [1,2,3,4,5,6,7,8,9]
def do_str_add(no):
for i in xrange(no):
xx = 'abcdef' + 'ghijlk'
def do_str_join(no):
for i in xrange(no):
xx = ''.join(('abcdef', 'ghijlk'))
def do_str_double_join(no):
for i in xrange(no):
a = 'abcdef'
b = ''.join(('ghijlk', 'aaaaaaa'))
xx = ''.join( (a, b) )
def do_str_join_extend(no):
for i in xrange(no):
a = ['abcdef']
a.extend( ('ghijlk', 'aaaaaaa') )
xx = ''.join( a )
import cStringIO as StringIO
def do_plus(no):
a = "a"*4096
for i in xrange(no):
b = ""
for j in range(40):
b += a
def do_join(no):
a = "a"*4096
for i in xrange(no):
b = []
for j in range(40):
b.append( a )
''.join(b)
import sys
sys.path.append('puka')
from puka import simplebuffer
def do_simplebuffer(no):
a = "a"*4096
for i in xrange(no):
b = simplebuffer.SimpleBuffer()
for j in range(40):
b.write( a )
b.read()
b.flush()
#tests = [do_tuple, do_list,
#tests = [do_str_add, do_str_join]
#tests = [do_str_join_extend, do_str_double_join]
tests = [do_simplebuffer, do_plus, do_join]
for test in tests:
print '%r' % test
a=time.time()
test(10000)
b=time.time()
print '%6.0fms' % ((b-a)*1000.0,)