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
| #!/usr/bin/env python
#coding=utf-8
from time import clock
import pickle,cPickle
print 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
te = clock()
with open("test.txt", 'w') as f:
for oneTitle in ('Title ' + str(i) for i in xrange(1,11)):
pickle.dump(oneTitle, f)
tf = clock()
a = tf-te
te = clock()
with open("test.txt", 'r') as f:
try:
while True:
oneVar = pickle.load(f)
#print oneVar
except:
pass
tf = clock()
b = tf-te
print 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
te = clock()
with open("testu.txt", 'wb') as f:
for oneTitle in ('Title ' + str(i) for i in xrange(1,11000)):
cPickle.dump(oneTitle, f, cPickle.HIGHEST_PROTOCOL)
tf = clock()
c = tf-te
te = clock()
with open("testu.txt", 'rb') as f:
try:
while True:
oneVar = cPickle.load(f, cPickle.HIGHEST_PROTOCOL)
#print oneVar
except:
pass
tf = clock()
d = tf-te
print 'pickle',
print '\n\tEcriture : ',a ,' Lecture : ', b
print 'cPickle',
print '\n\tEcriture : ',c ,' Lecture : ', d |
Partager