Last active
August 29, 2015 14:08
-
-
Save lmacken/f38389869e69d511a0b7 to your computer and use it in GitHub Desktop.
Benchmarks the fastest way to pull 'rawhide' out of 'atomic-compose-rawhide.service' in Python
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
#!/bin/sh -x | |
# 1000000 loops, best of 3: 1.29 usec per loop | |
python3 -m timeit --setup "import re" "re.match(r'atomic-compose-(.*)\.service', 'atomic-compose-rawhide.service').groups()[0]" | |
# 1000000 loops, best of 3: 0.807 usec per loop | |
python3 -m timeit --setup "import re; r = re.compile(r'atomic-compose-(.*)\.service')" "r.match('atomic-compose-rawhide.service').groups()[0]" | |
# 1000000 loops, best of 3: 0.575 usec per loop | |
python3 -m timeit "'atomic-compose-rawhide.service'.split('.')[0].split('-')[-1]" | |
# 1000000 loops, best of 3: 0.507 usec per loop | |
python3 -m timeit "'atomic-compose-rawhide.service'.replace('atomic-compose-', '').replace('.service', '')" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment