test: Set up flattening benchmarks#3686
Conversation
Reviewer's GuideAdds pytest-based benchmark tests that exercise singer_sdk.helpers._flattening functions (flatten_key, flatten_record, flatten_schema) across short/long key inputs and wide/deep record and schema structures to measure performance characteristics under different shapes and depths of data. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3686 +/- ##
=======================================
Coverage 94.21% 94.21%
=======================================
Files 73 73
Lines 6208 6208
Branches 763 763
=======================================
Hits 5849 5849
Misses 267 267
Partials 92 92
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance
Performance Changes
Comparing |
8fc9667 to
3a161eb
Compare
3a161eb to
6036d9e
Compare
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/benchmarks/test_flattening.py" line_range="15" />
<code_context>
+ flatten_schema,
+)
+
+NUMBER_OF_RUNS = 250
+
+
</code_context>
<issue_to_address>
**suggestion (testing):** Manual inner loop over `NUMBER_OF_RUNS` may fight against pytest-benchmark’s own timing controls
Wrapping each benchmarked call in a `run()` that loops `NUMBER_OF_RUNS` times duplicates pytest-benchmark’s own iteration control and can distort or obscure the timing results. Instead, pass the operation directly to `benchmark` (e.g. `benchmark(flatten_key, key, parents)` or `benchmark.pedantic(...)`) and, if needed, adjust the number of rounds via the fixture configuration rather than a custom loop.
Suggested implementation:
```python
from singer_sdk.helpers._flattening import (
flatten_key,
flatten_record,
flatten_schema,
)
from __future__ import annotations
import itertools
import pytest
from singer_sdk.helpers._flattening import (
flatten_key,
flatten_record,
flatten_schema,
```
```python
```
```python
def test_flatten_key_benchmark(benchmark, key, parents):
benchmark(flatten_key, key, parents)
```
```python
def test_flatten_record_benchmark(benchmark, record, schema):
benchmark(flatten_record, record, schema)
```
```python
def test_flatten_schema_benchmark(benchmark, schema):
benchmark(flatten_schema, schema)
```
If you want multiple rounds or warmup behavior, configure this via pytest-benchmark instead of a manual loop, e.g.:
- In `pytest.ini` or `pyproject.toml`, set options such as `benchmark_min_rounds`, `benchmark_max_time`, `benchmark_warmup` as needed.
- Alternatively, if you need more control per-test, you can use `benchmark.pedantic(flatten_key, args=(key, parents), iterations=1, rounds=250)` instead of the simple `benchmark(...)` call, which still avoids a custom inner loop while keeping iteration control with pytest-benchmark.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
6036d9e to
be9c26d
Compare
SSIA
Summary by Sourcery
Tests: