-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from NDari/master
Add benchmarking script
- Loading branch information
Showing
6 changed files
with
213 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,6 @@ _testmain.go | |
*.exe | ||
*.test | ||
*.prof | ||
|
||
vendor | ||
vendor/* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[[constraint]] | ||
name = "github.com/chewxy/math32" | ||
version = "1.0.0" | ||
|
||
[[constraint]] | ||
name = "github.com/stretchr/testify" | ||
version = "1.1.4" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// +build !sse,!avx | ||
|
||
package vecf32 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/chewxy/math32" | ||
) | ||
|
||
/* BENCHMARKS */ | ||
|
||
func _vanillaVecAdd(a, b []float32) { | ||
for i := range a { | ||
a[i] += b[i] | ||
} | ||
} | ||
|
||
func BenchmarkVecAdd(b *testing.B) { | ||
x := Range(0, niceprime) | ||
y := Range(niceprime, 2*niceprime) | ||
|
||
for n := 0; n < b.N; n++ { | ||
Add(x, y) | ||
} | ||
} | ||
|
||
func BenchmarkVanillaVecAdd(b *testing.B) { | ||
x := Range(0, niceprime) | ||
y := Range(niceprime, 2*niceprime) | ||
|
||
for n := 0; n < b.N; n++ { | ||
_vanillaVecAdd(x, y) | ||
} | ||
} | ||
|
||
func _vanillaVecSub(a, b []float32) { | ||
for i := range a { | ||
a[i] -= b[i] | ||
} | ||
} | ||
|
||
func BenchmarkVecSub(b *testing.B) { | ||
x := Range(0, niceprime) | ||
y := Range(niceprime, 2*niceprime) | ||
|
||
for n := 0; n < b.N; n++ { | ||
Sub(x, y) | ||
} | ||
} | ||
|
||
func BenchmarkVanillaVecSub(b *testing.B) { | ||
x := Range(0, niceprime) | ||
y := Range(niceprime, 2*niceprime) | ||
|
||
for n := 0; n < b.N; n++ { | ||
_vanillaVecSub(x, y) | ||
} | ||
} | ||
|
||
func _vanillaVecMul(a, b []float32) { | ||
for i := range a { | ||
a[i] *= b[i] | ||
} | ||
} | ||
|
||
func BenchmarkVecMul(b *testing.B) { | ||
x := Range(0, niceprime) | ||
y := Range(niceprime, 2*niceprime) | ||
|
||
for n := 0; n < b.N; n++ { | ||
Mul(x, y) | ||
} | ||
} | ||
|
||
func BenchmarkVanillaVecMul(b *testing.B) { | ||
x := Range(0, niceprime) | ||
y := Range(niceprime, 2*niceprime) | ||
|
||
for n := 0; n < b.N; n++ { | ||
_vanillaVecMul(x, y) | ||
} | ||
} | ||
|
||
func _vanillaVecDiv(a, b []float32) { | ||
for i := range a { | ||
a[i] /= b[i] | ||
} | ||
} | ||
|
||
func BenchmarkVecDiv(b *testing.B) { | ||
x := Range(0, niceprime) | ||
y := Range(niceprime, 2*niceprime) | ||
|
||
for n := 0; n < b.N; n++ { | ||
Div(x, y) | ||
} | ||
} | ||
|
||
func BenchmarkVanillaVecDiv(b *testing.B) { | ||
x := Range(0, niceprime) | ||
y := Range(niceprime, 2*niceprime) | ||
|
||
for n := 0; n < b.N; n++ { | ||
_vanillaVecDiv(x, y) | ||
} | ||
} | ||
|
||
func _vanillaVecSqrt(a []float32) { | ||
for i, v := range a { | ||
a[i] = math32.Sqrt(v) | ||
} | ||
} | ||
|
||
func BenchmarkVecSqrt(b *testing.B) { | ||
x := Range(0, niceprime) | ||
|
||
for n := 0; n < b.N; n++ { | ||
Sqrt(x) | ||
} | ||
} | ||
|
||
func BenchmarkVanillaVecSqrt(b *testing.B) { | ||
x := Range(0, niceprime) | ||
|
||
for n := 0; n < b.N; n++ { | ||
_vanillaVecSqrt(x) | ||
} | ||
} | ||
|
||
func _vanillaVecInverseSqrt(a []float32) { | ||
for i, v := range a { | ||
a[i] = 1.0 / math32.Sqrt(v) | ||
} | ||
} | ||
|
||
func BenchmarkVecInvSqrt(b *testing.B) { | ||
x := Range(0, niceprime) | ||
|
||
for n := 0; n < b.N; n++ { | ||
InvSqrt(x) | ||
} | ||
} | ||
|
||
func BenchmarkVanillaVecInvSqrt(b *testing.B) { | ||
x := Range(0, niceprime) | ||
|
||
for n := 0; n < b.N; n++ { | ||
_vanillaVecInverseSqrt(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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
set -ex | ||
|
||
benchtime=${1:-1s} | ||
|
||
go test -bench . -benchtime $benchtime | ||
go test -tags='sse' -bench . -benchtime $benchtime | ||
go test -tags='avx' -bench . -benchtime $benchtime | ||
|
||
# travis compiles commands in script and then executes in bash. By adding | ||
# set -e we are changing the travis build script's behavior, and the set | ||
# -e lives on past the commands we are providing it. Some of the travis | ||
# commands are supposed to exit with non zero status, but then continue | ||
# executing. set -x makes the travis log files extremely verbose and | ||
# difficult to understand. | ||
# | ||
# see travis-ci/travis-ci#5120 | ||
set +ex |