Hi, this is an extension of my other ask for help creating a rust version of the applicative sequence function. While I have been able to replicate the function (with some help) Ive yet to find decent performance and would like to understand why.
I've created a little repo with some alternative functions and one that uses multi_cartesian_product
from Itertools
:
Here is the repo: repo
These are the performance results I get:
test tests::multi_cartesian_product_test ... bench: 9,441 ns/iter (+/- 933)
test tests::sequence2_test ... bench: 20,458 ns/iter (+/- 1,710)
test tests::sequence_idiomatic_test ... bench: 20,919 ns/iter (+/- 2,039)
test tests::sequence_test ... bench: 20,754 ns/iter (+/- 2,069)
test result: ok. 0 passed; 0 failed; 0 ignored; 4 measured; 0 filtered out
With an F# version I'm getting a lot different results:
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated |
|-------------- |---------:|----------:|----------:|------:|--------:|-------:|------:|------:|----------:|
| Sequence | 3.768 us | 0.0433 us | 0.0384 us | 1.00 | 0.00 | 2.8992 | - | - | 8.9 KB |
| Sequence_Comp | 4.417 us | 0.0500 us | 0.0467 us | 1.17 | 0.02 | 2.3117 | - | - | 7.09 KB |
You can see the F# results are quite different, ~3x faster than multi_cartesian_product_test
. I would like to understand why the rust version is slower and understand what I can do to speed it up