github.com/pidato/unsafe@v0.1.4/cgo/call_test.go (about) 1 package cgo 2 3 import ( 4 "github.com/pidato/unsafe/cgo/cgo" 5 "runtime" 6 "testing" 7 "time" 8 ) 9 10 func BenchmarkCall(b *testing.B) { 11 b.Run("Assembly Trampoline Call", func(b *testing.B) { 12 for i := 0; i < b.N; i++ { 13 NonBlocking((*byte)(cgo.Stub), 0, 0) 14 } 15 }) 16 b.Run("CGO Trampoline Call", func(b *testing.B) { 17 for i := 0; i < b.N; i++ { 18 cgo.Blocking((*byte)(cgo.Stub), 0, 0) 19 } 20 }) 21 b.Run("CGO Standard", func(b *testing.B) { 22 for i := 0; i < b.N; i++ { 23 cgo.CGO() 24 } 25 }) 26 } 27 28 func TestSleep(t *testing.T) { 29 runtime.LockOSThread() 30 defer runtime.UnlockOSThread() 31 for i := 0; i < 10000; i++ { 32 NonBlocking((*byte)(cgo.Sleep), uintptr(time.Second), 0) 33 println(time.Now().UnixNano()) 34 } 35 }