Skip to content

Commit

Permalink
Added new benchmarks and updated README accordingly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver, Jonathan committed Jun 4, 2014
1 parent 24104f4 commit a1c7e3c
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Disruptor: Writer, Await One | 3.5 ns/op
Disruptor: Writer, Await Many | 1.0 ns/op
Disruptor: SharedWriter, Reserve One | 13.6 ns/op
Disruptor: SharedWriter, Reserve Many | 2.5 ns/op
Disruptor: SharedWriter, Reserve One, Contended Write | nn.n ns/op
Disruptor: SharedWriter, Reserve Many, Contended Write | nn.n ns/op
Disruptor: SharedWriter, Reserve One, Contended Write | 56.9 ns/op
Disruptor: SharedWriter, Reserve Many, Contended Write | 3.5 ns/op

When In Doubt, Use Channels
----------------------------
Expand Down
93 changes: 93 additions & 0 deletions benchmark-disruptor/shared_writer_contended_write_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package benchmarks

import (
"runtime"
"testing"

"github.com/smartystreets/go-disruptor"
)

func BenchmarkSharedWriterReserveOneContendedWrite(b *testing.B) {
runtime.GOMAXPROCS(3)
defer runtime.GOMAXPROCS(2)

ringBuffer := [RingBufferSize]int64{}
controller := disruptor.
Configure(RingBufferSize).
WithConsumerGroup(SampleConsumer{&ringBuffer}).
BuildShared()
controller.Start()
defer controller.Stop()
writer := controller.Writer()

iterations := int64(b.N)
b.ReportAllocs()
b.ResetTimer()

go func() {
sequence := disruptor.InitialSequenceValue
for sequence < iterations {
sequence = writer.Reserve(ReserveOne)
ringBuffer[sequence&RingBufferMask] = sequence
writer.Commit(sequence, sequence)
}
}()

sequence := disruptor.InitialSequenceValue
for sequence < iterations {
sequence = writer.Reserve(ReserveOne)
ringBuffer[sequence&RingBufferMask] = sequence
writer.Commit(sequence, sequence)
}

b.StopTimer()
}

func BenchmarkSharedWriterReserveManyContendedWrite(b *testing.B) {
runtime.GOMAXPROCS(3)
defer runtime.GOMAXPROCS(2)

ringBuffer := [RingBufferSize]int64{}
controller := disruptor.
Configure(RingBufferSize).
WithConsumerGroup(noopConsumer{}).
BuildShared()
controller.Start()
defer controller.Stop()
writer := controller.Writer()

iterations := int64(b.N)
b.ReportAllocs()
b.ResetTimer()

go func() {
previous, current := disruptor.InitialSequenceValue, disruptor.InitialSequenceValue
for current < iterations {
current = writer.Reserve(ReserveMany)

for i := previous + 1; i <= current; i++ {
ringBuffer[i&RingBufferMask] = i
}

writer.Commit(previous+1, current)
previous = current
}
}()
previous, current := disruptor.InitialSequenceValue, disruptor.InitialSequenceValue
for current < iterations {
current = writer.Reserve(ReserveMany)

for i := previous + 1; i <= current; i++ {
ringBuffer[i&RingBufferMask] = i
}

writer.Commit(previous+1, current)
previous = current
}

b.StopTimer()
}

type noopConsumer struct{}

func (this noopConsumer) Consume(lower, upper int64) {}

0 comments on commit a1c7e3c

Please sign in to comment.