gomoni / it

iterator library for go using a rangefunc experiment
MIT License
27 stars 2 forks source link

remove `iter.Pull` and `iter.Pull2` usages #10

Closed DmitriyMV closed 7 months ago

DmitriyMV commented 7 months ago

The whole idea is that you can range over functions themselves without additional wrapper types. You only need iter.Pull and iter.Pull2 when you plan to store the iterable between iterations (stateful iterator). Otherwise, you are just losing performance for context switches.

Benchmarks on my Mac M1 before applying changes:

goos: darwin
goarch: arm64
pkg: github.com/gomoni/it
BenchmarkRangeFilter
BenchmarkRangeFilter-10              489       2362737 ns/op
BenchmarkItFilterSlice
BenchmarkItFilterSlice-10             16      67850156 ns/op
BenchmarkItFilterFor
BenchmarkItFilterFor-10               25      47034218 ns/op
PASS

After the changes:

goos: darwin
goarch: arm64
pkg: github.com/gomoni/it
BenchmarkRangeFilter
BenchmarkRangeFilter-10              474       2359972 ns/op
BenchmarkItFilterSlice
BenchmarkItFilterSlice-10            274       4270057 ns/op
BenchmarkItFilterFor
BenchmarkItFilterFor-10              393       3044019 ns/op
PASS

The loss of speed it still there, but now it's around 1.5 to 2 times.