Added simple benchmark for single writer disruptor.
diff --git a/benchmarks/blocking_channel_test.go b/benchmarks/blocking_channel_test.go
index f7097c6..2070631 100644
--- a/benchmarks/blocking_channel_test.go
+++ b/benchmarks/blocking_channel_test.go
@@ -6,6 +6,8 @@
func BenchmarkBlockingChannel(b *testing.B) {
iterations := int64(b.N)
+ b.ReportAllocs()
+ b.ResetTimer()
channel := make(chan int64, blockingChannelBufferSize)
go func() {
diff --git a/benchmarks/non_blocking_channel_test.go b/benchmarks/non_blocking_channel_test.go
index 2fab6ee..26be72f 100644
--- a/benchmarks/non_blocking_channel_test.go
+++ b/benchmarks/non_blocking_channel_test.go
@@ -6,6 +6,8 @@
func BenchmarkNonBlockingChannel(b *testing.B) {
iterations := int64(b.N)
+ b.ReportAllocs()
+ b.ResetTimer()
channel := make(chan int64, nonBlockingChannelBufferSize)
go func() {
diff --git a/benchmarks/single_writer_test.go b/benchmarks/single_writer_test.go
new file mode 100644
index 0000000..2a5eba9
--- /dev/null
+++ b/benchmarks/single_writer_test.go
@@ -0,0 +1,43 @@
+package benchmarks
+
+import (
+ "runtime"
+ "testing"
+
+ "github.com/smartystreets/go-disruptor"
+)
+
+const RingSize = 1024 * 16
+
+func BenchmarkSingleWriter(b *testing.B) {
+ written, read := disruptor.NewCursor(), disruptor.NewCursor()
+ reader := disruptor.NewReader(read, written, written)
+ writer := disruptor.NewWriter(written, read, RingSize)
+
+ iterations := int64(b.N)
+ b.ReportAllocs()
+ b.ResetTimer()
+
+ go func() {
+ for i := int64(0); i < iterations; i++ {
+ if lower, upper := writer.Reserve(1); upper >= 0 {
+ writer.Commit(lower, upper)
+ }
+ }
+ }()
+
+ for {
+ _, upper := reader.Receive()
+ if upper >= 0 {
+ reader.Commit(upper)
+
+ if upper+1 == iterations {
+ break
+ }
+ }
+ }
+}
+
+func init() {
+ runtime.GOMAXPROCS(2)
+}