Skip to content

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Dec 27, 2023

Description of proposed changes

Follow-up to #2908, this is where we mark the unit tests for any PyGMT functions we want to benchmark with the @pytest.mark.benchmark decorator.

Benchmark report at https://codspeed.io/GenericMappingTools/pygmt/branches/pytest/mark-benchmark-part2

See #2924 (comment) below on which new tests have been marked for benchmarking. Will prioritize PyGMT functions that use temporary files, and low-level clib functions that should be benchmarked. General discussion on which tests to mark can go in #2910.

Part 2 of addressing #2910. Covers test functions from test_binstats to test_filter1d according to the list in #2910 (comment).

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@weiji14 weiji14 added maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog labels Dec 27, 2023
@weiji14 weiji14 added this to the 0.11.0 milestone Dec 27, 2023
@weiji14 weiji14 self-assigned this Dec 27, 2023
@weiji14 weiji14 linked an issue Dec 27, 2023 that may be closed by this pull request
Copy link

codspeed-hq bot commented Dec 27, 2023

CodSpeed Performance Report

Merging #2924 will not alter performance

⚠️ No base runs were found

Falling back to comparing pytest/mark-benchmark-part2 (4c1f1e9) with main (8be628e)

Summary

✅ 64 untouched benchmarks

🆕 34 new benchmarks

Benchmarks breakdown

Benchmark main pytest/mark-benchmark-part2 Change
🆕 test_put_matrix N/A 125.9 ms N/A
🆕 test_dataarray_to_matrix_works N/A 10.5 ms N/A
🆕 test_load_libgmt N/A 951.1 µs N/A
🆕 test_blockmean_input_xyz N/A 412.3 ms N/A
🆕 test_blockmedian_input_table_matrix N/A 603.7 ms N/A
🆕 test_accessor_set_geographic_cartesian_roundtrip N/A 928.5 µs N/A
🆕 test_virtualfile_from_data_required_z_matrix[Dataset-vector] N/A 64.8 ms N/A
🆕 test_blockmode_input_dataframe N/A 621.6 ms N/A
🆕 test_virtual_file N/A 444.2 ms N/A
🆕 test_put_matrix_grid N/A 331.1 ms N/A
🆕 test_binstats_no_outgrid N/A 154 ms N/A
🆕 test_put_vector_string_dtype N/A 143.4 ms N/A
🆕 test_call_module N/A 46.7 ms N/A
🆕 test_virtualfile_from_vectors_one_string_or_object_column[object] N/A 47.2 ms N/A
🆕 test_virtualfile_from_vectors_one_string_or_object_column[str] N/A 47.2 ms N/A
🆕 test_virtualfile_from_vectors N/A 451.2 ms N/A
🆕 test_put_strings N/A 14.7 ms N/A
🆕 test_virtualfile_from_data_required_z_matrix[array-matrix] N/A 49.4 ms N/A
🆕 test_config_format_date_map N/A 233.4 ms N/A
🆕 test_virtualfile_from_data_required_z_matrix[DataFrame-vector] N/A 51.3 ms N/A
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Comment on lines +22 to +34
@pytest.mark.benchmark
def test_load_remote_dataset_benchmark_with_region():
"""
Benchmark loading a remote dataset with 'region'.
"""
data = load_remote_dataset_wrapper(resolution="01d", region=[-10, 10, -5, 5])
assert data.name == "seafloor_age"
assert data.attrs["long_name"] == "age of seafloor crust"
assert data.attrs["cpt"] == "@earth_age.cpt"
assert data.attrs["units"] == "Myr"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.gmt.registration == 0
assert data.shape == (11, 21)
Copy link
Member Author

@weiji14 weiji14 Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of benchmarking all the various load_earth_* functions, I just made created a new one that tests the _load_remote_dataset function, and it should cover the refactoring happening at #2917. Note that this test is somewhat duplicating test_earth_age_01d_with_region, but should be ok I hope.

Comment on lines 59 to 62
@pytest.mark.benchmark
def test_figure_repr():
"""
Make sure that figure output's PNG and HTML printable representations look
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was a little unsure which test to benchmark for figure.py, so I picked this one that tests __repr_png__, since it goes through the savefig and _preview calls.

Comment on lines +183 to 186
@pytest.mark.benchmark
def test_earth_relief_holes():
"""
Check that the @earth_relief_20m_holes.grd dataset loads without errors.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only benchmarking test_earth_relief_holes since it calls both pygmt.which and pygmt.io.load_dataarray. The other sample datasets call pygmt.which and pd.read_csv only.

@weiji14 weiji14 added the needs review This PR has higher priority and needs review. label Jan 6, 2024
@weiji14 weiji14 marked this pull request as ready for review January 6, 2024 09:38
@weiji14 weiji14 enabled auto-merge (squash) January 6, 2024 09:41
@weiji14 weiji14 removed the needs review This PR has higher priority and needs review. label Jan 6, 2024
@weiji14 weiji14 disabled auto-merge January 6, 2024 10:47
@weiji14 weiji14 merged commit 1a103ce into main Jan 6, 2024
@weiji14 weiji14 deleted the pytest/mark-benchmark-part2 branch January 6, 2024 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants