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

Replace Unbuffered channels with buffered channels. #1642

Closed
arijitAD opened this issue Jun 15, 2021 · 1 comment · Fixed by #1668
Closed

Replace Unbuffered channels with buffered channels. #1642

arijitAD opened this issue Jun 15, 2021 · 1 comment · Fixed by #1668
Assignees

Comments

@arijitAD
Copy link
Contributor

Issue summary

  • Use buffered channel by default.
  • Buffered channel(size: 100) is 3x faster than the unbuffered channel because context switching between go routines takes time.
func BenchmarkUnbufferedChannelEmptyStruct(b *testing.B) {
	// BenchmarkUnbufferedChannelEmptyStruct-16    	 6310321	       181.6 ns/op
	ch := make(chan struct{})
	go func() {
		for {
			<-ch
		}
	}()
	for i := 0; i < b.N; i++ {
		ch <- struct{}{}
	}
}

func BenchmarkBufferedChannelEmptyStruct10(b *testing.B) {
	// BenchmarkBufferedChannelEmptyStruct1-16    	16444933	        69.14 ns/op
	ch := make(chan struct{}, 10)
	go func() {
		for {
			<-ch
		}
	}()
	for i := 0; i < b.N; i++ {
		ch <- struct{}{}
	}
}

func BenchmarkBufferedChannelEmptyStruct100(b *testing.B) {
	// BenchmarkBufferedChannelEmptyStruct10-16    	23277656	        45.66 ns/op
	ch := make(chan struct{}, 100)
	go func() {
		for {
			<-ch
		}
	}()
	for i := 0; i < b.N; i++ {
		ch <- struct{}{}
	}
}

Other information and links

@github-actions
Copy link

github-actions bot commented Dec 3, 2021

🎉 This issue has been resolved in version 0.6.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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 a pull request may close this issue.

3 participants