benchmark.js icon indicating copy to clipboard operation
benchmark.js copied to clipboard

Only async is used from the options passed into Benchmark.prototype.run(options).

Open Myaushka opened this issue 11 years ago • 5 comments

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.

Myaushka avatar Feb 11 '14 01:02 Myaushka

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.

bnjmnt4n avatar Feb 11 '14 03:02 bnjmnt4n

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.

jdalton avatar Feb 11 '14 06:02 jdalton

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.

Myaushka avatar Feb 13 '14 23:02 Myaushka

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
            })

ghost avatar Jul 08 '15 20:07 ghost

@joelrich

Is it really the idea to set all other options like this?

Benchmark.options.maxTime = 1;

Default options yep.

jdalton avatar Jul 08 '15 21:07 jdalton