Skip to content
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

feat: base measureFunction API #271

Merged
merged 24 commits into from
Oct 11, 2023
Merged

Conversation

mdjastrzebski
Copy link
Member

@mdjastrzebski mdjastrzebski commented Nov 25, 2022

Summary

Resolves #224

async function measureFunction(
  fn: () => void,
  options?: { runs?: number, dropWorst?: number },
): Promise<MeasureResults>

API for measuring execution time of regular JS functions. It works similarly to render measures, but instead of using React.Profiler to measure renders stats of component, it just measures the execution duration of JS function.

It's intended to be used for any JS apps (not only React/RN) or libraries.

Scope:

  • Minimal Viable API
  • Unit Tests
  • Perf Tests
  • Update Docs
  • Update Output report wording / separate tables
  • Rebase on main
  • Measure timestamps using performance.now()
  • Add type: MeasureType to PerformanceEntry and CompareEntry
  • Display measurement type in output files (MD, JSON, console)
  • Provide 'render' default for baseline tests lacking the 'type' property

Test plan

Added unit tests and perf tests using measureFunction

@changeset-bot
Copy link

changeset-bot bot commented Nov 25, 2022

⚠️ No Changeset found

Latest commit: 30c0767

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2022

Performance Comparison Report

  • Current: 1e4e6b5 - 2023-10-11 20:04:23Z
  • Baseline: main (8c69317) - 2023-10-11 20:03:35Z

Significant Changes To Duration

Name Type Duration Count
Async Component render 301.8 ms → 310.8 ms (+9.0 ms, +3.0%) 7 → 7
Show details
Name Type Duration Count
Async Component render Baseline
Mean: 301.8 ms
Stdev: 11.0 ms (3.6%)
Runs: 317 313 309 307 303 302 299 297 292 279

Current
Mean: 310.8 ms
Stdev: 15.9 ms (5.1%)
Runs: 337 331 325 314 313 303 299 299 296 291
Baseline
Mean: 7
Stdev: 0 (0.0%)
Runs: 7 7 7 7 7 7 7 7 7 7

Current
Mean: 7
Stdev: 0 (0.0%)
Runs: 7 7 7 7 7 7 7 7 7 7

Meaningless Changes To Duration

Show entries
Name Type Duration Count
Other Component 20 render 181.6 ms → 182.7 ms (+1.1 ms, +0.6%) 4 → 4
Other Component 10 legacy scenario render 182.5 ms → 182.9 ms (+0.4 ms, ±0.0%) 4 → 4
Other Component 10 render 178.2 ms → 174.3 ms (-3.9 ms, -2.2%) 4 → 4
Show details
Name Type Duration Count
Other Component 20 render Baseline
Mean: 181.6 ms
Stdev: 9.7 ms (5.3%)
Runs: 202 200 193 191 188 187 183 182 181 181 181 178 178 176 175 175 173 172 171 164

Current
Mean: 182.7 ms
Stdev: 8.4 ms (4.6%)
Runs: 197 195 193 193 191 186 185 185 184 184 182 182 181 179 177 176 175 170 170 169
Baseline
Mean: 4
Stdev: 0 (0.0%)
Runs: 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4

Current
Mean: 4
Stdev: 0 (0.0%)
Runs: 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
Other Component 10 legacy scenario render Baseline
Mean: 182.5 ms
Stdev: 7.2 ms (4.0%)
Runs: 195 190 185 185 184 183 181 177 175 170

Current
Mean: 182.9 ms
Stdev: 12.2 ms (6.7%)
Runs: 203 200 189 184 183 183 179 174 169 165
Baseline
Mean: 4
Stdev: 0 (0.0%)
Runs: 4 4 4 4 4 4 4 4 4 4

Current
Mean: 4
Stdev: 0 (0.0%)
Runs: 4 4 4 4 4 4 4 4 4 4
Other Component 10 render Baseline
Mean: 178.2 ms
Stdev: 4.7 ms (2.6%)
Runs: 185 184 183 179 179 177 176 175 173 171

Current
Mean: 174.3 ms
Stdev: 8.5 ms (4.9%)
Runs: 190 182 181 177 175 172 171 167 166 162
Baseline
Mean: 4
Stdev: 0 (0.0%)
Runs: 4 4 4 4 4 4 4 4 4 4

Current
Mean: 4
Stdev: 0 (0.0%)
Runs: 4 4 4 4 4 4 4 4 4 4

Changes To Count

There are no entries

Added Scenarios

Name Type Duration Count
fib 32 function 388.9 ms 1
fib 31 function 244.9 ms 1
fib 30 function 151.0 ms 1
Show details
Name Type Duration Count
fib 32 function Current
Mean: 388.9 ms
Stdev: 2.6 ms (0.7%)
Runs: 391.8 391.5 390.5 390.4 390.2 388.8 388.5 387.0 386.3 383.4
Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
fib 31 function Current
Mean: 244.9 ms
Stdev: 0.6 ms (0.2%)
Runs: 245.5 245.5 245.3 245.3 245.1 244.9 244.9 244.5 244.5 243.6
Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
fib 30 function Current
Mean: 151.0 ms
Stdev: 1.5 ms (1.0%)
Runs: 153.7 152.6 152.5 151.3 151.2 151.1 150.0 149.9 149.2 149.1
Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1

Removed Scenarios

There are no entries

Generated by 🚫 dangerJS against 30c0767

Copy link
Collaborator

@Xiltyn Xiltyn left a comment

Choose a reason for hiding this comment

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

Where are we with this exactly? It's marked as WIP and I was just wandering if that's something you're still working on? @mdjastrzebski

packages/reassure-measure/src/measure-execution.tsx Outdated Show resolved Hide resolved
packages/reassure-measure/src/measure-execution.tsx Outdated Show resolved Hide resolved
@mdjastrzebski
Copy link
Member Author

@Xiltyn This is an new feature/direction for Reassure, where it allow for testing performance of node apps and/or JS libraries (e.g. open source). This PR is about prototyping the API, and since I am limited on OSS time, it is progressing slowly. However, I think that this is very interesting niche to explore

@mdjastrzebski mdjastrzebski changed the title feat: base measureExecution API (WIP) feat: base measureFunction API Apr 25, 2023
Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Looks like a good direction. Thinking about whether we should incorporate some warmup code – but does it make sense in our case where we disable JIT and force GC?

@mdjastrzebski
Copy link
Member Author

@thymikee what do you mean by warmup code? The worst (first) run of the function will be dropped, similar to how we process render measurements.

@thymikee
Copy link
Member

@mdjastrzebski e.g. here: https://github.com/krausest/js-framework-benchmark#about-the-benchmarks. AFAIK warmup is helpful when preparing the JS engine to fire up JIT, but maybe there's more to it

@mdjastrzebski mdjastrzebski marked this pull request as ready for review April 27, 2023 15:22
fix: lint

refactor: rename `measureExecution` to `UNSTABLE_measurePerformance`

feat: measurePerformanceInternal executs code number of times

feat: allow setting custom measure code

refactor: re-structure measure functions

refactor: cleanup tests

refactor: rename measure results type
@adhorodyski
Copy link
Contributor

@mdjastrzebski now ready for review, with a fallback value of render as a migration path for the missing 'type' property in any existing tests :)

@mdjastrzebski
Copy link
Member Author

Looks good! Let's merge it! 🦙🏄‍♂️

@mdjastrzebski mdjastrzebski merged commit 933a5a2 into main Oct 11, 2023
2 checks passed
@mdjastrzebski mdjastrzebski deleted the feature/measure-execution branch October 11, 2023 20:13
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.

[FEATURE] Ability to measure code execution time
4 participants