Last active
February 11, 2018 11:52
-
-
Save wtnb75/08aefa2a10208ccbf53b5e4cb105a1cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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