forked from smarty-prototypes/go-disruptor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new benchmarks and updated README accordingly.
- Loading branch information
Oliver, Jonathan
committed
Jun 4, 2014
1 parent
24104f4
commit a1c7e3c
Showing
2 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} |