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

Optimizations #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Optimizations #32

wants to merge 1 commit into from

Conversation

zbjornson
Copy link

Building arrays via arr[i] = x is ~45% faster than arr.push(x). See http://jsperf.com/sylvesterloops/2
Store references to mOrV.elements.
Inline loops instead of call out to map, which calls to forEach.

Building arrays via `arr[i] = x` is faster than `arr.push(x)`. Store
references to morv.elements.
@@ -271,7 +271,7 @@ Sylvester.Matrix.prototype = {
if (!this.isSquare) { return null; }
var els = [], n = this.elements.length;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zbjornson You know the length already in a lot these cases, you should use new Array(n) and then set the indexs x[i] = <val>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@megawac that actually seems detrimental in some browsers and only a minor improvement in others: http://jsperf.com/construct-array-of-fixed-size/2

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Specifically, I optimized for FF and chrome, and the gain in FF doesn't outweigh the loss in chrome.)

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 this pull request may close these issues.

2 participants