diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2019-10-10 05:28:39 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2019-10-10 05:38:29 -0400 |
commit | 032ac34a2388f60777431bb54cbcd7075dae7afd (patch) | |
tree | c0b7bbdd8abbd1f0328f236e82bdeda29c438e7a /lab | |
parent | 190d8bcea6085014b2ae6eff7256cc344419b19d (diff) | |
download | python-coveragepy-git-032ac34a2388f60777431bb54cbcd7075dae7afd.tar.gz |
A script for comparing run times
Diffstat (limited to 'lab')
-rwxr-xr-x | lab/compare_times.sh | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lab/compare_times.sh b/lab/compare_times.sh new file mode 100755 index 00000000..c5f20bd9 --- /dev/null +++ b/lab/compare_times.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt + +# A suggestion about how to get less hyperfine output: +# https://github.com/sharkdp/hyperfine/issues/223 +HYPERFINE='hyperfine -w 1 -s basic -r 10' + +cat > sourcefile1.py << EOF +import random + +def get_random_number(): + return random.randint(5, 20) +EOF + +cat > test_file1.py << EOF +import pytest +import sourcefile1 + +tests = tuple(f'test{i}' for i in range(1000)) + +@pytest.mark.parametrize("input_str", tests) +def test_speed(input_str): + print(input_str) + number = sourcefile1.get_random_number() + assert number <= 20 + assert number >= 5 +EOF + +rm -f .coveragerc + +$HYPERFINE 'python -m pytest test_file1.py' + +echo "Coverage 4.5.4" +pip install -q coverage==4.5.4 +$HYPERFINE 'python -m coverage run -m pytest test_file1.py' +$HYPERFINE 'python -m coverage run --branch -m pytest test_file1.py' +$HYPERFINE 'python -m pytest --cov=. --cov-report= test_file1.py' +$HYPERFINE 'python -m pytest --cov=. --cov-report= --cov-branch test_file1.py' + +echo "Coverage 5.0a8, no contexts" +pip install -q coverage==5.0a8 +$HYPERFINE 'python -m coverage run -m pytest test_file1.py' +$HYPERFINE 'python -m coverage run --branch -m pytest test_file1.py' +$HYPERFINE 'python -m pytest --cov=. --cov-report= test_file1.py' +$HYPERFINE 'python -m pytest --cov=. --cov-report= --cov-branch test_file1.py' + +echo "Coverage 5.0a8, with test contexts" +cat > .coveragerc <<EOF +[run] +dynamic_context = test_function +EOF + +$HYPERFINE 'python -m coverage run -m pytest test_file1.py' +$HYPERFINE 'python -m coverage run --branch -m pytest test_file1.py' +$HYPERFINE 'python -m pytest --cov=. --cov-report= test_file1.py' +$HYPERFINE 'python -m pytest --cov=. --cov-report= --cov-branch test_file1.py' + +echo "Pytest-cov contexts" +rm -f .coveragerc + +$HYPERFINE 'python -m pytest --cov=. --cov-report= --cov-context=test test_file1.py' +$HYPERFINE 'python -m pytest --cov=. --cov-report= --cov-branch --cov-context=test test_file1.py' |