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

remove iter.Pull and iter.Pull2 usages #10

Merged
merged 1 commit into from
Feb 28, 2024
Merged

remove iter.Pull and iter.Pull2 usages #10

merged 1 commit into from
Feb 28, 2024

Conversation

DmitriyMV
Copy link
Contributor

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.

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.
@vyskocilm vyskocilm merged commit f40661c into gomoni:main Feb 28, 2024
1 check passed
@DmitriyMV DmitriyMV deleted the remove-pull branch February 28, 2024 13:22
@DmitriyMV DmitriyMV mentioned this pull request Feb 28, 2024
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

Successfully merging this pull request may close these issues.

2 participants