aboutsummaryrefslogtreecommitdiff
path: root/bench_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'bench_test.go')
-rw-r--r--bench_test.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/bench_test.go b/bench_test.go
index 82aaba1..0b84715 100644
--- a/bench_test.go
+++ b/bench_test.go
@@ -8,14 +8,14 @@ import (
)
func BenchmarkAtomicGet(b *testing.B) {
- x := NewVar(0)
+ x := NewVar[int](0)
for i := 0; i < b.N; i++ {
AtomicGet(x)
}
}
func BenchmarkAtomicSet(b *testing.B) {
- x := NewVar(0)
+ x := NewVar[int](0)
for i := 0; i < b.N; i++ {
AtomicSet(x, 0)
}
@@ -24,16 +24,16 @@ func BenchmarkAtomicSet(b *testing.B) {
func BenchmarkIncrementSTM(b *testing.B) {
for i := 0; i < b.N; i++ {
// spawn 1000 goroutines that each increment x by 1
- x := NewVar(0)
+ x := NewVar[int](0)
for i := 0; i < 1000; i++ {
go Atomically(VoidOperation(func(tx *Tx) {
- cur := tx.Get(x).(int)
- tx.Set(x, cur+1)
+ cur := x.Get(tx)
+ x.Set(tx, cur+1)
}))
}
// wait for x to reach 1000
Atomically(VoidOperation(func(tx *Tx) {
- tx.Assert(tx.Get(x).(int) == 1000)
+ tx.Assert(x.Get(tx) == 1000)
}))
}
}
@@ -83,7 +83,7 @@ func BenchmarkReadVarSTM(b *testing.B) {
for i := 0; i < b.N; i++ {
var wg sync.WaitGroup
wg.Add(1000)
- x := NewVar(0)
+ x := NewVar[int](0)
for i := 0; i < 1000; i++ {
go func() {
AtomicGet(x)