Permalink
Browse files

micro: improve bench, fix cgo build and isolate

* Use .so instead of .a,
* Use local GOPATH to prevent contaminating client GOPATH,
* Use strconv.FormatUint instead of fmt.Sprintf,
* Make noise for bench errors.
  • Loading branch information...
1 parent 1f85b0b commit 7d19b52d3bb35c05d43d9fcaffe2103629e55805 @kortschak kortschak committed with jiahao Sep 22, 2015
Showing with 18 additions and 7 deletions.
  1. +3 −3 test/perf/micro/Makefile
  2. +2 −0 test/perf/micro/gopath/.gitignore
  3. +13 −4 test/perf/micro/perf.go
@@ -79,9 +79,9 @@ benchmarks/c%.csv: bin/perf%
benchmarks/fortran%.csv: bin/fperf%
for t in 1 2 3 4 5; do $<; done >$@
+benchmarks/go.csv: export GOPATH=$(abspath gopath)
benchmarks/go.csv: perf.go
- go get github.com/gonum/blas
- CGO_LDFLAGS="$(LIBBLAS) -lm" go install github.com/gonum/blas/cgo
+ CGO_LDFLAGS="-L$(JULIAHOME)/deps -lopenblas" go get github.com/gonum/blas/cgo
go get github.com/gonum/matrix/mat64
go get github.com/gonum/stat
for t in 1 2 3 4 5; do go run $<; done >$@
@@ -141,6 +141,6 @@ benchmarks.html: bin/table.pl benchmarks.csv
@$(call PRINT_PERL, $^ >$@)
clean:
- @rm -rf perf.h bin/perf* bin/fperf* benchmarks/*.csv benchmarks.csv mods *~ octave-core perf.log
+ @rm -rf perf.h bin/perf* bin/fperf* benchmarks/*.csv benchmarks.csv mods *~ octave-core perf.log gopath/*
.PHONY: all perf clean
@@ -0,0 +1,2 @@
+/pkg
+/src
@@ -16,7 +16,9 @@
package main
import (
+ "errors"
"fmt"
+ "log"
"math"
"math/cmplx"
"math/rand"
@@ -204,13 +206,20 @@ func assert(b *testing.B, t bool) {
func main() {
for _, bm := range benchmarks {
- print_perf(bm.name, runBenchmarkFor(bm.fn))
+ seconds, err := runBenchmarkFor(bm.fn)
+ if err != nil {
+ log.Fatalf("%s %s", bm.name, err)
+ }
+ print_perf(bm.name, seconds)
}
}
-func runBenchmarkFor(fn func(*testing.B)) (seconds float64) {
+func runBenchmarkFor(fn func(*testing.B)) (seconds float64, err error) {
bm := testing.Benchmark(fn)
- return bm.T.Seconds() / float64(bm.N)
+ if (bm == testing.BenchmarkResult{}) {
+ return 0, errors.New("failed")
+ }
+ return bm.T.Seconds() / float64(bm.N), nil
}
var benchmarks = []struct {
@@ -234,7 +243,7 @@ var benchmarks = []struct {
for i := 0; i < b.N; i++ {
for k := 0; k < 1000; k++ {
n := rnd.Uint32()
- m, _ := strconv.ParseUint(fmt.Sprintf("%x", n), 16, 32)
+ m, _ := strconv.ParseUint(strconv.FormatUint(uint64(n), 16), 16, 32)
if uint32(m) != n {
b.Fatal("incorrect value for m")
}

0 comments on commit 7d19b52

Please sign in to comment.