Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

range.sh

#!/bin/sh

PYTHON=python3

${PYTHON} -c 'from sys import version; print(version)'

timeit() { ${PYTHON} -m perf timeit --quiet --duplicate 200 "$@" }

for args in "10" "1, 2" "1, 2, 3"; do echo

# Actual benchmarks
echo -n "range($args):             "
timeit "range($args)"

done

list.sh

#!/bin/sh

PYTHON=python3

${PYTHON} -c 'from sys import version; print(version)'

timeit() { ${PYTHON} -m perf timeit --quiet --duplicate 200 "$@" }

for args in "()" "(1, 2)" "(1, 2, 3, 4, 5)"; do echo

# Actual benchmarks
echo -n "list($args):             "
timeit "list($args)"

done

Timings

Master

range(10): Mean +- std dev: 192 ns +- 14 ns

range(1, 2): Mean +- std dev: 215 ns +- 10 ns

range(1, 2, 3): Mean +- std dev: 224 ns +- 10 ns

list(()): Mean +- std dev: 122 ns +- 3 ns

list((1, 2)): Mean +- std dev: 148 ns +- 10 ns

list((1, 2, 3, 4, 5)): Mean +- std dev: 148 ns +- 4 ns

PEP 590

range(10): Mean +- std dev: 135 ns +- 3 ns

range(1, 2): Mean +- std dev: 153 ns +- 2 ns

range(1, 2, 3): Mean +- std dev: 159 ns +- 5 ns

list(()): Mean +- std dev: 84.5 ns +- 2.6 ns

list((1, 2)): Mean +- std dev: 107 ns +- 4 ns

list((1, 2, 3, 4, 5)): Mean +- std dev: 114 ns +- 4 ns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.