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

ci(bench): migrate benchmark tool benny to vitest #297

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sunrabbit123
Copy link

@sunrabbit123 sunrabbit123 commented Nov 1, 2024

The reason why I raised the PR is as follows.

  1. Benchmark order affects results
  2. if function result is not used, this function is not using
  3. Disclosure of incorrect information due to incorrect benchmarks

Proposal

  1. remove benny
  2. and use vitest

스크린샷 2024-11-01 오후 3 52 55

If this PR is accepted, there is also a foothold to replace all tests with bitest-based rather than just test.

@gvergnaud
Copy link
Owner

Interesting, so because of the ordering of test cases, the current benchmarks where biased toward native implementation and vitest's results show that ts-pattern's performance are more similar to native control flow statements. Am I interpreting this correctly?

Comment on lines 7 to 18
const input = (() => {
const map = {
0: { type: 'a' as const, value: { x: Math.random(), y: Math.random() } },
1: {
type: 'b' as const,
value: Math.random() > 0.5 ? [1, 2, 3, 4] : ['hello'],
},
2: { type: 'c' as const, age: Math.random(), name: 'acdfl' },
};

return map[inputIndex];
})();
Copy link
Owner

Choose a reason for hiding this comment

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

We should re-generate the input on every run instead of only once, otherwise we are always testing against the same object which could make results vary between runs, and could result in irrelevant JIT optimizations.

Copy link
Author

Choose a reason for hiding this comment

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

Nevertheless, the object creation time should be excluded from the benchmark.

Therefore, I am looking for ways to use setup.

I will ask you to review it again after working on it.

Copy link
Owner

Choose a reason for hiding this comment

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

I don't mind that the object creation is included in the benchmark as long as it's included in all cases. Its only purpose is to compare equivalent implementation of the same thing, so the absolute values aren't that important

const rand = () => Math.floor(Math.random() * 10) as Digit;

describe('ts-pattern-benchmark/random-digit', () => {
const digit = rand();
Copy link
Owner

Choose a reason for hiding this comment

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

same here

vitest.config.mts Outdated Show resolved Hide resolved
Signed-off-by: sunrabbit123 <[email protected]>
@sunrabbit123
Copy link
Author

interesting, so because of the ordering of test cases, the current benchmarks where biased toward native implementation and vitest's results show that ts-pattern's performance are more similar to native control flow statements. Am I interpreting this correctly?

What is certain is that Benny is a problematic benchmark tool.

As for whether the beatest is correct, I think it is better to check the benchmark result one more time after modifying it according to the review.

@sunrabbit123
Copy link
Author

next is changed benchmark result

스크린샷 2024-11-04 오전 11 45 56

I still don't feel the big gap.
What's the problem..

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.

2 participants