Add a benchmark assert
option to pre-run and test that it returns an expected result.
#8
Comments
Maybe something like var bench = Benchmark('foo', {
'assert': 6,
'fn': function() {
var a = 3 + 3;
return a;
}
}); If it didn't match it would error and call the |
I’ve been asked to add this as a feature to jsPerf in the past. I’m not sure how to create a good UI for it (I’m afraid things will become too bloated) but this would be good to have in Benchmark.js for sure! |
I've been demanding this since day one. Just some basic sanity check to make sure that each test is actually doing what we expect |
@subtleGradient Any preference on option name or is If no one as any major objection I will probably begin to add this into Benchmark.js. |
Nice, I always get an awkward feeling that perhaps my benchmarks are running code that doesn't quite make sense or are checking something other than intended. |
Assert sounds good to me |
+1 on naming it |
Other names could be: preflight, precheck, or pretest. I'll keep this ticket open for ideas. |
Whatever approach is taken, it would need to work with async tests as well. The Another approach would be to forego adding an assert equality check at all and instead have the user provide a function where they can use the assertion library of their choice and if the assertion fails, the user can call a method to abort the Benchmark. A functional approach allows the user more flexibility on the types and quantity of assertions desired. |
Yap, I'm punting this enhancement. |
Add a Benchmark
assert
option to pre-run and test that it returns an expected result.This can be useful to ensure snippets being tested at least return the same result.
The text was updated successfully, but these errors were encountered: