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

Confusing warning for benchmark start() and end() calls under 0.01s #20853

Closed
sgwilym opened this issue Oct 9, 2023 · 4 comments · Fixed by #20862
Closed

Confusing warning for benchmark start() and end() calls under 0.01s #20853

sgwilym opened this issue Oct 9, 2023 · 4 comments · Fixed by #20862
Assignees

Comments

@sgwilym
Copy link
Contributor

sgwilym commented Oct 9, 2023

Warning: start() and end() calls in "<benchmark>" are ignored because it averages less
than 0.01s per iteration. Remove them for better results.

This came up when I was trying to benchmark the 1000th insert into a data structure. Something like this:

Deno.bench(
	"1000th Insert",
	(bench) => {
		const tree = new FancyTree();

		// Here I set up things up...
		for (let i = 0; i < 1000; i++) {
			tree.insert(i);
		}

		bench.start();

		// And here is the bit I actually want to measure.
		// But I'm being told I shouldn't.
		tree.insert(1000);

		bench.end();
	},
);

I don't want to remove bench.start() and bench.end() because then I'll be measuring the duration of the 999 other inserts. So this warning doesn't really help me (nor does it help me understand why this 0.01s limitation is in place when it doesn't seem to apply elsewhere).

Related to #20272.

@nayeemrmn nayeemrmn self-assigned this Oct 9, 2023
@lino-levan
Copy link
Contributor

lino-levan commented Oct 9, 2023

Well the issue with this is that the benchmark ends so fast that most of the benchmark is spent in not doing your operation. It's essentially just noise. This is a warning to say "hey, this data is going to be super inaccurate, make your test longer!". I think it could be better worded.

@nayeemrmn
Copy link
Collaborator

nayeemrmn commented Oct 9, 2023

Specifically the part between the start and end is really short so using start and end will give a higher time than is accurate. But without accounting for the stuff outside maybe it shouldn't blindly suggest removing them. And maybe it shouldn't ignore them, just output a warning that results might be inaccurate.
Also the message is wrong about the time, it should be 0.01ms or 10µs.

@nayeemrmn
Copy link
Collaborator

Actually we should measure the total time (not between start/end) when deciding if the test is too short or not.

@sgwilym
Copy link
Contributor Author

sgwilym commented Oct 10, 2023

It's also a bit confusing as benchmarks which don't use start and stop seem perfectly content to measure things below 10µs.

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 a pull request may close this issue.

3 participants