benchmark.js
benchmark.js copied to clipboard
Only async is used from the options passed into Benchmark.prototype.run(options).
I see this line inside of run(options) that obviously overrides options that are passed in: options = { 'async': ((options = options && options.async) == null ? me.async : options) && support.timeout };
The documentation does not say that only the async option will be used.
What is the reason for this? It looks intentional; however, I spent a couple of hours debugging before I gradually concluded that my options were not being used, so I'm very frustrated.
Basically what this line does is check if you have enabled the async
option. Otherwise it will use the default, which is false
. It also checks to make sure timeouts are supported.
The documentation does not say that only the async option will be used.
It is the only option shown and the only option supported. We should make this more clear using JSDoc. So I'll mark this as a doc bug.
Thanks; it's true that it was the only thing shown, and yes, it looks deliberate and "by design" in the code, but examples are not usually exhaustive.
For what it's worth, I was trying to capture the benchmark itself in one of the options' callbacks. This would not be relevant except that I'm using Benchmark.js via Script#, so I was trying to work around the C# scoping rules.
Is it really the idea to set all other options like this?
Benchmark.options.maxTime = 1;
Edit: If you use a benchmark suite, then the correct way is to pass the options to add()
:
new Benchmark.Suite()
.add('...', function () {
// ...
}, {
maxTime: 1
})
@joelrich
Is it really the idea to set all other options like this?
Benchmark.options.maxTime = 1;
Default options yep.