Skip to content

Instantly share code, notes, and snippets.

@lmacken
Last active August 29, 2015 14:08
Show Gist options
  • Save lmacken/f38389869e69d511a0b7 to your computer and use it in GitHub Desktop.
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
#!/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