Skip to content

Conversation

ktrz
Copy link
Member

@ktrz ktrz commented Aug 3, 2025

This PR fixes an issue when the new benchmark results are using a different time unit than the previous one. This happens specifically when the benchmark values are very close to the boundary between 2 units, ex. 990 ns/iter and 1.1 us/iter. In that case, we need to normalize the newly coming results to the previously used unit so that the values are comparable.

  • extract addBenchmarkEntry function
  • normalize new entry values to match last entry units
  • handle <time>, <time>/iter and ops/<time> units

fixes #122

@ktrz ktrz self-assigned this Aug 3, 2025
@ktrz ktrz changed the title fix: time units are not normalized fix: time units are not normalized (issue #122) Aug 3, 2025
ktrz added 6 commits August 30, 2025 18:38
* extract addBenchmarkEntry function
* normalize new entry values to match last entry units
* normalize ops per time unit
* handle <time_unit>/iter unit
* add tests for write function
@ktrz ktrz force-pushed the fix/122-time-units-not-normalized branch from 3168d8d to 9bb96a6 Compare August 30, 2025 16:38
Copy link

codecov bot commented Aug 30, 2025

Codecov Report

❌ Patch coverage is 98.80952% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.07%. Comparing base (689894f) to head (ba0e547).

Files with missing lines Patch % Lines
src/write.ts 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #318      +/-   ##
==========================================
+ Coverage   88.12%   89.07%   +0.95%     
==========================================
  Files          10       15       +5     
  Lines         884      943      +59     
  Branches      187      199      +12     
==========================================
+ Hits          779      840      +61     
+ Misses        101       99       -2     
  Partials        4        4              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@NachoVazquez NachoVazquez left a comment

Choose a reason for hiding this comment

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

I'm not sure if you want to act on my comments. The PR looks great in general, and I was able to quickly grasp the context without knowing the tool too well. My comments are more style than behavior-oriented, so take it or leave it.

Good to go in any case. 🚀

} else {
const suites = entries[benchName];
// Get last suite which has different commit ID for alert comment
for (const e of suites.slice().reverse()) {

Choose a reason for hiding this comment

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

nit: alternatively you could do something like:

prevBench = suits.slice().reverse().find(e => e.commit.id !== benchEntry.commit.id)

it is exactly the same but less verbose

const currentRange = currenBenchResult.range;
const currentRangeInfo = extractRangeInfo(currentRange);

const normalizedValue = normalizeUnit(prevUnit, currentUnit, currenBenchResult.value);

Choose a reason for hiding this comment

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

suggestion: the naming here could be better, you are normalizing the value by calling a function named normalizeUnit and one line below you are creating a normalizedUnit variable.

Maybe a better name for the function is normalizeValueByUnit or something similar.

const UNIT_CONVERSION_MULTIPLIER = 1000;
const TIME_UNITS = ['s', 'ms', 'us', 'ns'];
const ITER_UNITS = TIME_UNITS.map((unit) => `${unit}/iter`);
const OPS_PER_TIME_UNIT = [...TIME_UNITS].reverse().map((unit) => `ops/${unit}`);

Choose a reason for hiding this comment

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

giga-nitpick: I noticed you have used two different cloning techniques on the same PR, maybe is better for consistency to pick one.

  1. [...previousValue]
  2. previousValue.slice()

Comment on lines +831 to +832
added.benches; // ?
expectedAdded.benches; // ?

Choose a reason for hiding this comment

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

Wallaby is that you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

catch2 time units are ignored when graphing and generating alerts
2 participants