-
-
Save flyser/6183740 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## This is on python 2.7: | |
In [1]: a = '12345678' | |
In [2]: %timeit [a[max(i-3,0):i] for i in range(len(a), 0, -3)][::-1] | |
1000000 loops, best of 3: 1.91 us per loop | |
In [3]: %timeit format(int(a), ',').split(',') | |
1000000 loops, best of 3: 1.62 us per loop | |
In [4]: %timeit [a[max(0,i):i+3] for i in range((len(a)-1)%3-2, len(a), 3)] | |
1000000 loops, best of 3: 1.67 us per loop | |
## And python 3.2: | |
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.58 us per loop | |
In [3]: %timeit format(int(a), ',').split(',') | |
1000000 loops, best of 3: 1.98 us per loop | |
In [4]: %timeit [a[max(0,i):i+3] for i in range((len(a)-1)%3-2, len(a), 3)] | |
100000 loops, best of 3: 2.45 us per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment