Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2013 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/6183623 to your computer and use it in GitHub Desktop.
Save anonymous/6183623 to your computer and use it in GitHub Desktop.
Timeit's, split numbers into threes
In [1]: a = '12345678'
In [2]: %timeit [a[max(i-3,0):i] for i in range(len(a), 0, -3)][::-1]
100000 loops, best of 3: 2.19 us per loop
In [3]: %timeit format(int(a), ',').split(',')
100000 loops, best of 3: 2.04 us per loop
In [4]: %timeit [a[max(0,i-2+(len(a)-1)%3):i+1+(len(a)-1)%3] for i in range(0, len(a), 3)]
100000 loops, best of 3: 2.91 us per loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment