#coding=utf8 import cStringIO import StringIO import time values = [] items = ['1,2,31,2,31,2,31,2,3'] * 10000000 #print items st = float(time.time()) for i in items: values.append(i) news = ''.join(values) print len(news) print 'list append cost time:%s'%(float(time.time()) - st) strio = cStringIO.StringIO() st = float(time.time()) for j in items: strio.write(j) print len(strio.getvalue()) print 'cStringIO cost time:%s'%(float(time.time()) - st) strio = StringIO.StringIO() st = float(time.time()) for j in items: strio.write(j) print len(strio.getvalue()) print 'StringIO cost time:%s'%(float(time.time()) - st)
python三种字符串拼接效率对比
最新推荐文章于 2024-05-08 11:11:35 发布