Skip to content

Instantly share code, notes, and snippets.

@tsailiming
Created February 10, 2016 08:53
Show Gist options
  • Save tsailiming/e2c5bc5554b1cfe56c17 to your computer and use it in GitHub Desktop.
Save tsailiming/e2c5bc5554b1cfe56c17 to your computer and use it in GitHub Desktop.
A quick mirobenchmark to benchmark the performance of Native Blas vs f2jblas
import org.apache.spark.mllib.linalg.{Vector, Vectors}
import com.github.fommil.netlib.{BLAS => NetlibBLAS, F2jBLAS}
import com.github.fommil.netlib.BLAS.{getInstance => NativeBLAS}
def time[R](block: => R): R = {
val t0 = System.nanoTime()
val result = block // call-by-name
val t1 = System.nanoTime()
println("Elapsed time: " + (t1 - t0)/1000000.0 + "ms")
result
}
var f2jBLAS = new F2jBLAS
var nativeBLAS = NativeBLAS
val dv1: Vector = Vectors.dense((1d to 1000000d by 1d).toArray)
time {nativeBLAS.ddot(dv1.size, dv1.toDense.values, 1, dv1.toDense.values, 1)}
time {f2jBLAS.ddot(dv1.size, dv1.toDense.values, 1, dv1.toDense.values, 1)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment