Last active
December 14, 2017 18:50
-
-
Save davidwtbuxton/9af0250ce66ccb64eee4214ab4ab070e to your computer and use it in GitHub Desktop.
Profiling different ways for testing if there's an empty string value
This file contains hidden or 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
$ python -m timeit -s "a, b, c, d, e, f = 'abcdef'" "any(v for v in (a, b, c, d, e, f) if v == '')" | |
1000000 loops, best of 3: 1.51 usec per loop | |
$ python -m timeit -s "a, b, c, d, e, f = 'abcdef'" "'' in (a, b, c, d, e, f)" | |
1000000 loops, best of 3: 0.36 usec per loop | |
$ python -m timeit -s "a, b, c, d, e, f = ' bcdef'" "any(v for v in (a, b, c, d, e, f) if v == '')" | |
1000000 loops, best of 3: 1.52 usec per loop | |
$ python -m timeit -s "a, b, c, d, e, f = ' bcdef'" "'' in (a, b, c, d, e, f)" | |
1000000 loops, best of 3: 0.354 usec per loop | |
$ python -m timeit -s "a, b, c, d, e, f = 'abcde '" "any(v for v in (a, b, c, d, e, f) if v == '')" | |
1000000 loops, best of 3: 1.49 usec per loop | |
$ python -m timeit -s "a, b, c, d, e, f = 'abcde '" "'' in (a, b, c, d, e, f)" | |
1000000 loops, best of 3: 0.357 usec per loop | |
$ python --version | |
Python 2.7.14 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment