github.com/moontrade/wavm-go@v0.3.2-0.20220316110326-d229dd66ad65/unsafecgo/call_test.go (about)

     1  package unsafecgo
     2  
     3  import (
     4  	"github.com/moontrade/wavm-go/unsafecgo/cgo"
     5  	"runtime"
     6  	"testing"
     7  	"time"
     8  )
     9  
    10  func BenchmarkCall(b *testing.B) {
    11  	b.Run("asm", func(b *testing.B) {
    12  		for i := 0; i < b.N; i++ {
    13  			NonBlocking((*byte)(cgo.Stub), 0, 0)
    14  		}
    15  	})
    16  	b.Run("libcCall", func(b *testing.B) {
    17  		for i := 0; i < b.N; i++ {
    18  			cgo.NonBlocking((*byte)(cgo.Stub), 0, 0)
    19  		}
    20  	})
    21  	b.Run("cgo", func(b *testing.B) {
    22  		for i := 0; i < b.N; i++ {
    23  			cgo.CGO()
    24  		}
    25  	})
    26  	b.Run("cgo trampoline", func(b *testing.B) {
    27  		for i := 0; i < b.N; i++ {
    28  			cgo.Blocking((*byte)(cgo.Stub), 0, 0)
    29  		}
    30  	})
    31  }
    32  
    33  func TestSleep(t *testing.T) {
    34  	runtime.LockOSThread()
    35  	defer runtime.UnlockOSThread()
    36  	for i := 0; i < 10000; i++ {
    37  		NonBlocking((*byte)(cgo.Usleep), uintptr(time.Second), 0)
    38  		//cgo.NonBlocking((*byte)(cgo.Usleep), uintptr(time.Second/1000), 0)
    39  		//cgo.DoUsleep(int64(time.Second/1000))
    40  		println(time.Now().UnixNano())
    41  	}
    42  }