-
-
Notifications
You must be signed in to change notification settings - Fork 85
Add performance test #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+75
−1
Merged
Add performance test #275
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8425756
add performance test
jagerber-qtm b3e66a1
try codspeed
jagerber-qtm d532874
process time for complexity
jagerber-qtm c6c6128
test complexity
jagerber-qtm 992a37a
codspeed CI
jagerber-qtm 4153cf2
adjust test running
jagerber-qtm d0120b3
adjust test more
jagerber-qtm 2dd07b9
only run on latest ubuntu
jagerber-qtm 4480808
slightly different ufloat summation
jagerber-qtm c19d373
comments
jagerber-qtm a052ae1
Merge remote-tracking branch 'origin/feature/benchmark_test' into fea…
jagerber-qtm c9b46a5
benchmark multiple N values
jagerber-qtm 5f4d55a
reverse order of decorators
jagerber-qtm f98349e
benchmark fixture?
jagerber-qtm eb29951
run the benchmark directly, maybe codspeed will handle benchmarking.
jagerber-qtm 6470a24
refactor and clean up the tests
jagerber-qtm afa1712
Changelog
jagerber-qtm 6927711
Update test_performance.py
andrewgsavage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| from math import log10 | ||
| import time | ||
| import timeit | ||
|
|
||
| import pytest | ||
|
|
||
| from uncertainties import ufloat | ||
|
|
||
|
|
||
| def repeated_summation(num): | ||
| """ | ||
| generate and sum many floats together, then calculate the standard deviation of the | ||
| output. Under the lazy expansion algorithm, the uncertainty remains non-expanded | ||
| until a request is made to calculate the standard deviation. | ||
| """ | ||
| result = sum(ufloat(1, 0.1) for _ in range(num)).std_dev | ||
| return result | ||
|
|
||
|
|
||
| def test_repeated_summation_complexity(): | ||
| """ | ||
| Test that the execution time is linear in summation length | ||
| """ | ||
| approx_execution_time_per_n = 10e-6 # 10 us | ||
| target_test_duration = 1 # 1 s | ||
|
|
||
| n_list = [10, 100, 1000, 10000, 100000] | ||
| t_list = [] | ||
| for n in n_list: | ||
| """ | ||
| Choose the number of repetitions so that the test takes target_test_duration | ||
| assuming the timing of a single run is approximately | ||
| N * approx_execution_time_per_n | ||
| """ | ||
| # Choose the number of repetitions so that the test | ||
| single_rep_duration = n * approx_execution_time_per_n | ||
| num_reps = int(target_test_duration / single_rep_duration) | ||
|
|
||
| t_tot = timeit.timeit( | ||
| lambda: repeated_summation(n), | ||
| number=num_reps, | ||
| timer=time.process_time, | ||
| ) | ||
| t_single = t_tot / num_reps | ||
| t_list.append(t_single) | ||
| n0 = n_list[0] | ||
| t0 = t_list[0] | ||
| for n, t in zip(n_list[1:], t_list[1:]): | ||
| # Check that the plot of t vs n is linear on a log scale to within 10% | ||
| # See PR 275 | ||
| assert 0.9 * log10(n / n0) < log10(t / t0) < 1.1 * log10(n / n0) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("num", (10, 100, 1000, 10000, 100000)) | ||
| @pytest.mark.benchmark | ||
|
jagerber48 marked this conversation as resolved.
|
||
| def test_repeated_summation_speed(num): | ||
| repeated_summation(num) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen a test similar to this that kept randomly failing so I don't know how reliable this test will be.
I think test_repeated_summation_speed will catch any increases in time so these tests are testing the same thing. I'm not opposed to this test- we can leave it in for now, and if it we find it unreliable we can remove it.
I'll add a link to PR with the graph you plotted as it helps makes sense of this test. It'll be good to see this plotted for your other PR too.