1.2ns per operation.
diff --git a/example/main.go b/example/main.go
index 51fc14d..15f8ad3 100644
--- a/example/main.go
+++ b/example/main.go
@@ -21,20 +21,21 @@
written, read := disruptor.NewCursor(), disruptor.NewCursor()
- consumer := SampleConsumer{}
- reader := disruptor.NewReader(read, written, written, consumer)
+ // reader := disruptor.NewReader(read, written, written, SampleConsumer{})
started := time.Now()
- go reader.Start()
- publish(written, read, reader)
+ // go reader.Start()
+ go consume(written, read)
+ publish(written, read)
+ // reader.Stop()
// consume(written, read)
finished := time.Now()
fmt.Println(Iterations, finished.Sub(started))
}
-func publish(written, read *disruptor.Cursor, reader *disruptor.Reader) {
+func publish(written, read *disruptor.Cursor) {
previous := disruptor.InitialSequenceValue
gate := disruptor.InitialSequenceValue
@@ -54,59 +55,56 @@
written.Sequence = next
previous = next
}
-
- reader.Stop()
}
// func consume(reader *disruptor.Reader) {
-// sleeps := 0
+func consume(written, read *disruptor.Cursor) {
+ sleeps := 0
+ consumer := SampleConsumer{}
-// // consumer := SampleConsumer{}
+ previous := int64(-1)
+ gate := int64(-1)
+ for previous < Iterations {
+ current := previous + 1
+ gate = written.Sequence
-// // previous := int64(-1)
-// // gate := int64(-1)
-// // for previous < Iterations {
-// // current := previous + 1
-// // gate = written.Sequence
+ if current <= gate {
-// // if current <= gate {
+ for current < gate {
+ current += consumer.Consume(current, gate)
+ }
+ // for current <= gate {
+ // if ringBuffer[current&BufferMask] > 0 {
+ // }
-// // for current < gate {
-// // current += consumer.Consume(current, gate)
-// // }
-// // // for current <= gate {
+ // current++
+ // }
-// // // if ringBuffer[current&BufferMask] > 0 {
-// // // }
+ previous = gate
+ read.Sequence = gate
+ } else {
+ sleeps++
+ time.Sleep(time.Microsecond)
+ }
+ }
-// // // current++
-// // // }
+ fmt.Println("Consumer sleeps:", sleeps)
-// // previous = gate
-// // read.Sequence = gate
-// // } else {
-// // sleeps++
-// // time.Sleep(time.Microsecond)
-// // }
-// // }
+ // // for sequence, gate := int64(0), int64(0); sequence < Iterations; sequence++ {
-// fmt.Println("Consumer sleeps:", sleeps)
+ // // // for gate <= sequence {
+ // // // gate = written.Sequence
+ // // // if gate <= sequence {
+ // // // time.Sleep(time.Microsecond)
+ // // // }
+ // // // }
-// // for sequence, gate := int64(0), int64(0); sequence < Iterations; sequence++ {
+ // // // if ringBuffer[sequence&BufferMask] > 0 {
+ // // // }
-// // // for gate <= sequence {
-// // // gate = written.Sequence
-// // // if gate <= sequence {
-// // // time.Sleep(time.Microsecond)
-// // // }
-// // // }
-
-// // // if ringBuffer[sequence&BufferMask] > 0 {
-// // // }
-
-// // // read.Sequence = sequence
-// // }
-// }
+ // // // read.Sequence = sequence
+ // // }
+}
// // type Consumer interface {
// // Consume(lower, upper int64)
@@ -115,8 +113,8 @@
type SampleConsumer struct{}
func (this SampleConsumer) Consume(current, gate int64) int64 {
- // if ringBuffer[current&BufferMask] > 0 {
- // }
+ if ringBuffer[current&BufferMask] > 0 {
+ }
return 1
}