github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/bench/call/call_test.go (about) 1 package call 2 3 import ( 4 "runtime" 5 "testing" 6 ) 7 8 func BenchmarkNopGo(b *testing.B) { 9 for i := 0; i < b.N; i++ { 10 Nop() 11 } 12 } 13 14 func BenchmarkNopCGO(b *testing.B) { 15 for i := 0; i < b.N; i++ { 16 CNop() 17 } 18 } 19 20 func BenchmarkAdd2(b *testing.B) { 21 total := int32(0) 22 for i := 0; i < b.N; i++ { 23 total = Add2(total, int32(i)) 24 } 25 runtime.KeepAlive(total) 26 } 27 28 func BenchmarkCAdd2(b *testing.B) { 29 total := int32(0) 30 for i := 0; i < b.N; i++ { 31 total = CAdd2(total, int32(i)) 32 } 33 runtime.KeepAlive(total) 34 } 35 36 func BenchmarkArgs1(b *testing.B) { 37 n := NewDeviceCreateInfo 38 x0 := n() 39 for i := 0; i < b.N; i++ { 40 Args1(x0) 41 } 42 Release(x0) 43 } 44 45 func BenchmarkArgs2(b *testing.B) { 46 n := NewDeviceCreateInfo 47 x0, x1 := n(), n() 48 for i := 0; i < b.N; i++ { 49 Args2(x0, x1) 50 } 51 Release(x0, x1) 52 } 53 54 func BenchmarkArgs4(b *testing.B) { 55 n := NewDeviceCreateInfo 56 x0, x1, x2, x3 := n(), n(), n(), n() 57 for i := 0; i < b.N; i++ { 58 Args4(x0, x1, x2, x3) 59 } 60 Release(x0, x1, x2, x3) 61 } 62 63 func BenchmarkCArgs1(b *testing.B) { 64 n := NewDeviceCreateInfo 65 x0 := n() 66 for i := 0; i < b.N; i++ { 67 CArgs1(x0) 68 } 69 Release(x0) 70 } 71 72 func BenchmarkCArgs2(b *testing.B) { 73 n := NewDeviceCreateInfo 74 x0, x1 := n(), n() 75 for i := 0; i < b.N; i++ { 76 CArgs2(x0, x1) 77 } 78 Release(x0, x1) 79 } 80 81 func BenchmarkCArgs4(b *testing.B) { 82 n := NewDeviceCreateInfo 83 x0, x1, x2, x3 := n(), n(), n(), n() 84 for i := 0; i < b.N; i++ { 85 CArgs4(x0, x1, x2, x3) 86 } 87 Release(x0, x1, x2, x3) 88 }