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

Optimization in optional parameters #1

Merged
merged 1 commit into from Feb 2, 2017

Conversation

Projects
None yet
2 participants
@wchiquito
Contributor

wchiquito commented Jan 25, 2017

Optimization in optional parameters.

Optimization in optional parameters
Optimization in optional parameters.
@todojs

This comment has been minimized.

Owner

todojs commented Jan 26, 2017

Umm, the difference between

options = options || {};

and

options || (options = {});

it's not clear. We has made an intensive benchmark and don't obtain a significative difference.

Do you obtain other result in your benchmarks?

@wchiquito

This comment has been minimized.

Contributor

wchiquito commented Jan 27, 2017

In general, assigning a variable is expensive (probably not significant in this case), and more so if it is to assign the same value. If the language used allows you to avoid it, it should be something to consider.

@todojs

This comment has been minimized.

Owner

todojs commented Feb 2, 2017

We have made an intensive benchmark and the result is this:

Your mode 21,341,474 iterations per second
Our mode 20,463,299 iterations per second

The test code is very simple:

benchmarkjs('option1', function() {
    option1({a: 1, b: 2});
    option1();
    function option1(options) {
        options = options || {};
    }
});
benchmarkjs('option2', function() {
    option2({a: 1, b: 2});
    option2();
    function option2(options) {
        options || (options = {});
    }
});

It's true, your approach is faster, but it is a "nano optimization" (millions of executions per seconds).

@todojs todojs merged commit 7e65b8d into todojs:master Feb 2, 2017

@wchiquito wchiquito deleted the wchiquito:patch-1 branch Feb 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment