github.com/webmafia/fast@v0.10.0/atomic_int32_pair_test.go (about) 1 package fast 2 3 import ( 4 "fmt" 5 "sync/atomic" 6 "testing" 7 ) 8 9 func ExampleAtomicInt32Pair() { 10 var v AtomicInt32Pair 11 12 for i := 0; i < 100; i++ { 13 v.Add(1, -1) 14 } 15 16 fmt.Println(v.Load()) 17 18 // Output: 100 -100 19 } 20 21 func BenchmarkAtomicInt32Pair_Add(b *testing.B) { 22 var v AtomicInt32Pair 23 24 b.ResetTimer() 25 26 for i := 0; i < b.N; i++ { 27 v.Add(1, -1) 28 } 29 } 30 31 func BenchmarkAtomicInt64_Add(b *testing.B) { 32 var v atomic.Int64 33 34 b.ResetTimer() 35 36 for i := 0; i < b.N; i++ { 37 v.Add(1) 38 } 39 } 40 41 func BenchmarkAtomicInt32_Add(b *testing.B) { 42 var v atomic.Int32 43 44 b.ResetTimer() 45 46 for i := 0; i < b.N; i++ { 47 v.Add(1) 48 } 49 } 50 51 func BenchmarkAtomicInt32Pair_Add_Parallell(b *testing.B) { 52 var v AtomicInt32Pair 53 54 b.ResetTimer() 55 56 b.RunParallel(func(p *testing.PB) { 57 for p.Next() { 58 v.Add(1, -1) 59 } 60 }) 61 } 62 63 func BenchmarkAtomicInt64_Add_Parallell(b *testing.B) { 64 var v atomic.Int64 65 66 b.ResetTimer() 67 68 b.RunParallel(func(p *testing.PB) { 69 for p.Next() { 70 v.Add(1) 71 } 72 }) 73 } 74 75 func BenchmarkAtomicInt32_Add_Parallell(b *testing.B) { 76 var v atomic.Int32 77 78 b.ResetTimer() 79 80 b.RunParallel(func(p *testing.PB) { 81 for p.Next() { 82 v.Add(1) 83 } 84 }) 85 }