-
Notifications
You must be signed in to change notification settings - Fork 106
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
Faster BatList.cartesian_product #997
Comments
Maybe send a PR, I'd like to see the two versions side by side. |
OK, I'll do a PR soon. I was also thinking providing I would also be happy with iterators:
Do you agree? |
this implementation avoids the call to List.concat as explained in issue ocaml-batteries-team#997
Can't you use Seq over a cartesian product to get an iterator? |
This is to avoid constructing a list if we only need to iter or fold over it. If you want to use Seq, you can also construct the list with You can see in the test above that with 2 lists of lengths 2_000 and 4_000, the result is a list of length 8_000_000. |
please, send a PR for your improved cartesian_product. |
It seems that we could make
BatList.cartesian_product
a little bit faster by using 2fold_left
instead of 2List.map
so that we avoid the cost of callingList.concat
at the end:The only thing is that we need to reverse the 2 input lists if we want to preserve the same output order than the current implementation. The version that doesn't reverse the input lists is just a little bit faster, which could be interesting for people that don't mind about the order of the output.
I only "benched" with
time
:The text was updated successfully, but these errors were encountered: