Skip to content

Instantly share code, notes, and snippets.

@nictuku
Last active January 4, 2016 13:59
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 nictuku/8631259 to your computer and use it in GitHub Desktop.
Save nictuku/8631259 to your computer and use it in GitHub Desktop.
Improving the Julia microbench for Go
package main
import (
"fmt"
"math/rand"
"time"
"github.com/gonum/matrix/mat64"
// Switch to cblas for the C implementation of BLAS.
blas "github.com/gonum/blas/goblas"
)
func randMatMul(n int) *mat64.Dense {
a := mat64.NewDense(n, n, nil)
b := mat64.NewDense(n, n, nil)
for i := 0; i < n; i++ {
for k := 0; k < n; k++ {
a.Set(i, k, rand.Float64())
b.Set(i, k, rand.Float64())
}
}
r := mat64.NewDense(n, n, nil)
r.Mul(a, b)
return r
}
func main() {
mat64.Register(blas.Blas{})
tmin := time.Hour
for i := 0; i < 5; i++ {
t := time.Now()
c := randMatMul(1000)
if c.At(0, 0) < 0 {
panic("Unexpected negative number")
}
d := time.Since(t)
if d < tmin {
tmin = d
}
}
fmt.Printf("took %v\n", tmin)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment