Last active
December 25, 2015 01:19
-
-
Save queertypes/6893852 to your computer and use it in GitHub Desktop.
A benchmark comparing different ways of extracting a scheme from a URI 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
# A benchmark comparing different ways of extracting a scheme from a URI in Python | |
# common code | |
# import statements | |
uri = 'redis://localhost:27017' | |
# pypy-2.1: after warm up | |
In [12]: %timeit urlparse.urlparse(uri).scheme | |
1000000 loops, best of 3: 298 ns per loop | |
In [11]: %timeit uri.rpartition('://')[0] | |
10000000 loops, best of 3: 61.1 ns per loop | |
# Python 3.3.2 | |
In [10]: %timeit parse.urlparse(uri) | |
100000 loops, best of 3: 5.45 us per loop | |
In [11]: %timeit uri.rpartition('://') | |
1000000 loops, best of 3: 229 ns per loop | |
# Python 2.7.5 | |
In [12]: %timeit urlparse.urlparse(uri) | |
100000 loops, best of 3: 2.93 µs per loop | |
In [13]: %timeit uri.rpartition('://') | |
1000000 loops, best of 3: 244 ns per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment