Created
December 30, 2020 12:11
-
-
Save mawillcockson/e6001bcc114620aa5084cb61ddb9a799 to your computer and use it in GitHub Desktop.
Compare Manhattan distance calculations implemented in python
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
| # https://twitter.com/IsntTrivial/status/1344185584013742086 | |
| echo "sum(map(abs, map(operator.sub, p, q)))" | |
| python -m timeit \ | |
| -s "import operator;p=q=range(-10_000, 10_000, 1);" \ | |
| -s "def manhattan_distance(p, q): return sum(map(abs, map(operator.sub, p, q)))" \ | |
| "manhattan_distance(p, q)" | |
| echo "" | |
| echo "sum(abs(x - y) for x, y in zip(p, q))" | |
| python -m timeit \ | |
| -s "p=q=range(-10_000, 10_000, 1);" \ | |
| -s "def manhattan_distance(p, q): return sum(abs(x - y) for x, y in zip(p, q))" \ | |
| "manhattan_distance(p, q)" | |
| echo "" | |
| echo "sum([abs(x - y) for x, y in zip(p, q)])" | |
| python -m timeit \ | |
| -s "p=q=range(-10_000, 10_000, 1);" \ | |
| -s "def manhattan_distance(p, q): return sum([abs(x - y) for x, y in zip(p, q)])" \ | |
| "manhattan_distance(p, q)" |
Author
mawillcockson
commented
Dec 30, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment