Benchmarked new writer--4.35ns per operation (compared to 1.2), but with better API.
diff --git a/example/main.go b/example/main.go
index 9219326..61ffb05 100644
--- a/example/main.go
+++ b/example/main.go
@@ -26,6 +26,7 @@
started := time.Now()
reader.Start()
publish(writer)
+ // publish(written, read)
reader.Stop()
finished := time.Now()
fmt.Println(Iterations, finished.Sub(started))
@@ -39,6 +40,24 @@
}
}
+// func publish(written, read *disruptor.Cursor) {
+// previous := disruptor.InitialSequenceValue
+// gate := disruptor.InitialSequenceValue
+
+// for previous <= Iterations {
+// next := previous + 1
+// wrap := next - BufferSize
+
+// for wrap > gate {
+// gate = read.Sequence
+// }
+
+// ringBuffer[next&BufferMask] = next
+// written.Sequence = next
+// previous = next
+// }
+// }
+
type SampleConsumer struct{}
func (this SampleConsumer) Consume(lower, upper int64) {
diff --git a/writer.go b/writer.go
index 809a04e..9ba8a73 100644
--- a/writer.go
+++ b/writer.go
@@ -31,7 +31,8 @@
func (this *Writer) Reserve() int64 {
// next := this.previous + 1
- wrap := (this.previous + 1) - this.capacity // next - this.capacity
+ // wrap := next - this.capacity
+ wrap := (this.previous + 1) - this.capacity
if wrap > this.gate {
min := this.upstream.Read(0) // interface call: 1.20ns per operation
@@ -42,8 +43,10 @@
this.gate = min // update stateful variable: 1.20ns per operation
}
- this.previous++ // this.previous = next
- return this.previous // return next
+ this.previous++
+ // this.previous = next
+ return this.previous
+ // return next
}
func (this *Writer) Commit(sequence int64) {