Skip to content

Instantly share code, notes, and snippets.

@wtnb75
Last active February 11, 2018 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtnb75/08aefa2a10208ccbf53b5e4cb105a1cc to your computer and use it in GitHub Desktop.
Save wtnb75/08aefa2a10208ccbf53b5e4cb105a1cc to your computer and use it in GitHub Desktop.
package cgotest
import (
//#cgo LDFLAGS: -lm
//#include <math.h>
"C"
"math"
)
func CSin(x float64) float64 {
return float64(C.sin(C.double(x)))
}
func Sin(x float64) float64 {
return math.Sin(x)
}
package cgotest
import (
"math"
"testing"
)
func BenchmarkCSin(b *testing.B) {
for i := 0; i < b.N; i++ {
CSin(float64(i) / 1000.0)
}
}
func BenchmarkSin(b *testing.B) {
for i := 0; i < b.N; i++ {
Sin(float64(i) / 1000.0)
}
}
func BenchmarkMSin(b *testing.B) {
for i := 0; i < b.N; i++ {
math.Sin(float64(i) / 1000.0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment