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

feat: add ContainsOne method #134

Merged
merged 2 commits into from
Dec 26, 2023
Merged

feat: add ContainsOne method #134

merged 2 commits into from
Dec 26, 2023

Conversation

vladvalkov
Copy link
Contributor

@vladvalkov vladvalkov commented Dec 26, 2023

This PR solves issue #118 by adding ContainsOne method, which does not cause additional allocations.
Also added some benchmarks to compare performance in different cases.

@deckarep
Copy link
Owner

@vladvalkov - hey thanks for this! I forgot that this method was talked about as an improvement to mitigate allocations. Thanks for the holiday present!

LGTM =)

@deckarep deckarep merged commit 4a7d053 into deckarep:main Dec 26, 2023
6 checks passed
@deckarep
Copy link
Owner

Nice win, thanks for the thorough benchmarking!

BenchmarkContainsComparison1Unsafe/Contains-12         	61960590	        19.25 ns/op	       8 B/op	       1 allocs/op
BenchmarkContainsComparison1Unsafe/Contains_slice-12   	160231255	         7.539 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsComparison1Unsafe/ContainsOne-12      	221081941	         5.431 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsComparison1Safe/Contains-12           	38062934	        31.10 ns/op	       8 B/op	       1 allocs/op
BenchmarkContainsComparison1Safe/Contains_slice-12     	59746304	        20.06 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsComparison1Safe/ContainsOne-12        	72793695	        16.53 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsComparison10Unsafe/Contains-12        	 5283321	       219.6 ns/op	      80 B/op	      10 allocs/op
BenchmarkContainsComparison10Unsafe/Contains_slice-12  	11263368	       106.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsComparison10Unsafe/ContainsOne-12     	14033839	        85.38 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsComparison10Safe/Contains-12          	 3539056	       334.7 ns/op	      80 B/op	      10 allocs/op
BenchmarkContainsComparison10Safe/Contains_slice-12    	 5102409	       235.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsComparison10Safe/ContainsOne-12       	 6373026	       188.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsComparison100Unsafe/Contains-12       	  405156	      2643 ns/op	     800 B/op	     100 allocs/op
BenchmarkContainsComparison100Unsafe/Contains_slice-12 	  934239	      1125 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsComparison100Unsafe/ContainsOne-12    	 1321592	       908.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsComparison100Safe/Contains-12         	  329816	      3508 ns/op	     800 B/op	     100 allocs/op
BenchmarkContainsComparison100Safe/Contains_slice-12   	  492885	      2419 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsComparison100Safe/ContainsOne-12      	  618212	      1949 ns/op	       0 B/op	       0 allocs/op

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