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

Improve performance of max and min #212

Closed
pseudosavant opened this issue Sep 7, 2014 · 3 comments
Closed

Improve performance of max and min #212

pseudosavant opened this issue Sep 7, 2014 · 3 comments

Comments

@pseudosavant
Copy link

Using Math.max.apply(null, array) is ~100x faster on large arrays than the current max and min implementation.

Note that Chrome has a limit of ~100k arguments when using .apply so arrays larger than 100k values need to be done in batches. See here.

@Yaffle
Copy link
Contributor

Yaffle commented Sep 7, 2014

but Math.max converts all arguments to numbers...
Also why do you think, native Math.max can be faster?

@pseudosavant
Copy link
Author

Check out this: http://jsbin.com/vativ/1/edit?js,console. FWIW, running that on my phone (what I'm on right now) is actually ~200x faster.

I've tried quite a few ways of doing this and using Math.max is easily the fastest. The code to do it in math.js wouldn't be near as elegant as the current version you have (nice use of closures) but it's not too bad. I'm thinking of coding it up myself so look for a pull request.

BTW, this looks like a great library. High quality code, good documentation. That's why I'm actually interested in contributing.

Paul


From: Viktormailto:[email protected]
Sent: ‎9/‎6/‎2014 9:27 PM
To: josdejong/mathjsmailto:[email protected]
Cc: Paul Ellismailto:[email protected]
Subject: Re: [mathjs] Improve performance of max and min (#212)

but Math.max converts all arguments to numbers...
Also why do you think, native Math.max can be faster?


Reply to this email directly or view it on GitHub:
#212 (comment)

@josdejong
Copy link
Owner

math.js is slower because it's doing type-checking of all array values.

Performance improvements for matrix operations in general is on the radar, see for example #275. Is it ok with you to close this issue?

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

No branches or pull requests

3 participants