Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: bigeagle on Apr 8th, 2012  |  syntax: Python  |  size: 0.51 KB  |  views: 341  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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)