Tripled barrier performance.
diff --git a/barrier.go b/barrier.go
index 0f89d52..d36e3d0 100644
--- a/barrier.go
+++ b/barrier.go
@@ -2,11 +2,9 @@
func (this Barrier) Load() int64 {
minimum := MaxSequenceValue
- length := this.length
- upstream := this.upstream
- for i := 0; i < length; i++ {
- cursor := upstream[i].Load()
+ for i := 0; i < len(this); i++ {
+ cursor := this[i].Load()
if cursor < minimum {
minimum = cursor
}
@@ -16,13 +14,11 @@
}
func NewBarrier(upstream ...*Sequence) Barrier {
- length := len(upstream)
- target := make([]*Sequence, length, length)
- copy(target, upstream)
- return Barrier{length: length, upstream: target}
+ this := Barrier{}
+ for i := 0; i < len(upstream); i++ {
+ this = append(this, upstream[0])
+ }
+ return this
}
-type Barrier struct {
- length int
- upstream []*Sequence
-}
+type Barrier []*Sequence
diff --git a/barrier_test.go b/barrier_test.go
new file mode 100644
index 0000000..6ff674c
--- /dev/null
+++ b/barrier_test.go
@@ -0,0 +1,17 @@
+package main
+
+import "testing"
+
+func BenchmarkBarrierLoad(b *testing.B) {
+ upstream := NewSequence()
+ upstream.Store(42)
+ barrier := NewBarrier(upstream)
+
+ iterations := int64(b.N)
+ b.ReportAllocs()
+ b.ResetTimer()
+
+ for i := int64(0); i < iterations; i++ {
+ barrier.Load()
+ }
+}