timeit Timer import random string str random random for in xrange 10 s

1
2
3
4
5
6
7
>>> z = timeit.Timer("a+b+c+d+e+f+g+h+i+k", "import random; string=[str(random.random()) for x in xrange(10)];a, b, c, d, e, f, g, h, i, k = string")
>>> z.timeit()
1.0927922403545702
>>> x = timeit.Timer("''.join(string)", "import random; string=[str(random.random()) for x in xrange(10)]")
>>> x.timeit()
0.55238724474759238