-
Notifications
You must be signed in to change notification settings - Fork 97
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
Performance of Combination #75
Comments
I'm pretty sure itertools is written in c which is going to be way faster than js |
I think there's something else going on. Compare these two gists: https://gist.github.com/hildjj/1e5cf863c25a2f75f8a0ff4c1f8e51c0 (199.87s user) and https://gist.github.com/hildjj/082bf5104006fc8cf97f92324b2607a8 (0.70s user) You'll see that there is more than two orders of magnitude in difference between the performance of the same loop. |
Oh okay, that seems quite inefficient! Is the second implementation lexicographically ordered? |
I just checked to make sure it wasn't some weird interaction with the esm package by modifying your |
Yes, I think the second one is supposed to be lexicographically ordered. |
It's been a while ... but I found out part of the reason why it is so inefficient. This library bases all of their calculations on the index. All of the classes here have an In some ways this is useful. Mostly when you need the Unfortunately this is detrimental for efficiency. Unnecessarily inefficient. The If you, or others, only need efficient iteration of combinatics I'd recommend a module I developed based on Python's itertools package. It's available for npm and deno. The itertools c implementations are only 33% faster than these implementations! If you need additional calculations like |
This is indeed a big performance issue with this library, sadly even after several years it is not resolved... This respository demonstrates a huge performance degradation in js-cobinatorics library. To run the test simply do: $ git clone git@github.com:shahata/combinatorics-perfromance.git
$ npm install
$ node index.js The result will be something like:
It shows how the exact same iteration takes under 1 seconds in version 0.6.1 vs more than a minute in version 2.1.1 |
I recently wrote the same code against this library's
Combinations.of
and compared it to very similar code in Python usingitertools.combinations
. In both cases, I was taking combinations of 200 inputs 3 at a time (a mere 1,313,400 results), iterating over the results with for/of and doing a trivial amount of processing for each combination. The Python itertools version was several orders of magnitude faster for no apparent reason.input
is a list of 200 integers.JS code node 15.3.0:
Python 3.9.0:
The text was updated successfully, but these errors were encountered: