github.com/LaevusDexter/asmcgocall@v0.0.0-20200220061330-f484a47e9b97/examples/sum_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func sum(prms ...int) (res int) {
     8  	for _, i := range prms {
     9  		res += i
    10  	}
    11  
    12  	return
    13  }
    14  
    15  var sumExpected = sum(1, 2, 3, 4, 5)
    16  
    17  func TestSum(t *testing.T) {
    18  	res := sumAsmcgocall(1, 2, 3, 4, 5)
    19  
    20  	if sumExpected != int(res) {
    21  		t.Fatal("sumAsmcgocall...", "expected:", sumExpected, "got:", res)
    22  	}
    23  
    24  	res = sumCgocall(1, 2, 3, 4, 5)
    25  	if sumExpected != int(res) {
    26  		t.Fatal("sumCgocall...", "expected:", sumExpected, "got:", res)
    27  	}
    28  }
    29  
    30  func BenchmarkSumAsmcgocall(b *testing.B) {
    31  	for i := 0; i < b.N; i++ {
    32  		sumAsmcgocall(1, 2, 3, 4, 5)
    33  	}
    34  }
    35  
    36  func BenchmarkSumCgocall(b *testing.B) {
    37  	for i := 0; i < b.N; i++ {
    38  		sumCgocall(1, 2, 3, 4, 5)
    39  	}
    40  }