SHARE
TWEET

Untitled

bigeagle Apr 8th, 2012 484 Never
  1. #!/usr/bin/env python2
  2. # -*- coding:utf8 -*-
  3. import timeit
  4. import array
  5.  
  6. def f1(list):
  7.     return array.array('B', list).tostring()
  8. def f2(list):
  9.     return ''.join(list)
  10. def f3(list):
  11.     return ''.join(map(chr,list))
  12.  
  13. t1=timeit.Timer("f1([65,66,67,68])","from __main__ import f1,f2,f3")
  14. print t1.timeit(100000)
  15. t1=timeit.Timer("f2(['A','B','C','D'])","from __main__ import f1,f2,f3")
  16. print t1.timeit(100000)
  17. t1=timeit.Timer("f3([65,66,67,68])","from __main__ import f1,f2,f3")
  18. print t1.timeit(100000)
RAW Paste Data
Top