github.com/madokast/nopreempt@v1.0.3-0.20240125081507-3fa05aef38ed/nopreempt_benchmark_test.go (about) 1 package nopreempt 2 3 import ( 4 "sync" 5 "testing" 6 ) 7 8 func BenchmarkAdd(b *testing.B) { 9 var s int 10 for i := 0; i < b.N; i++ { 11 s += i // unix 0.3376 ns/op 12 } 13 } 14 15 func BenchmarkAddLock(b *testing.B) { 16 var s int 17 var mu sync.Mutex 18 for i := 0; i < b.N; i++ { 19 mu.Lock() 20 s += i // unix 5.359 ns/op 21 mu.Unlock() 22 } 23 } 24 25 func BenchmarkAddDisablePreempt(b *testing.B) { 26 var s int 27 for i := 0; i < b.N; i++ { 28 mp := AcquireM() 29 s += i // unix 3.498 ns/op 30 mp.Release() 31 } 32 }