Skip to content

Instantly share code, notes, and snippets.

@feynmanliang
Last active October 10, 2015 19:57
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 feynmanliang/bc64b82a1258c4e86b9a to your computer and use it in GitHub Desktop.
Save feynmanliang/bc64b82a1258c4e86b9a to your computer and use it in GitHub Desktop.

[SPARK-10478] SoftmaxFunction.eval Benchmarks Before/After PR 8648

Num Examples Num Classes Before Average Runtime (ms) After Average Runtime (ms)
1000 5 5.3315174999999995 0.4096546
1000 50 6.7308793 4.1289975
1000 250 21.5866622 21.25164
10000 5 4.2153461 4.145396
10000 50 42.2423785 41.0198213
10000 250 215.2192236 208.61861249999998
100000 5 43.517224899999995 41.2843315
100000 50 439.6628608 441.096843
100000 250 2158.0049358 2518.1192571999995

To Reproduce:

Remove private[ann] modifier to ml.ann.SoftmaxFunction, compile, paste into spark-shell.

First, paste in this:

import breeze.linalg.{DenseMatrix => BDM}
import org.apache.log4j._

import org.apache.spark.ml.ann.SoftmaxFunction

Logger.getRootLogger.setLevel(Level.OFF)

val numTrials = 10

val softmax = new SoftmaxFunction()

Then this:

for {
  numExamples <- Seq(1000, 10000, 100000);
  numClasses <- Seq(5, 50, 250)
} {
  val times = Seq.fill(numTrials) {
    val x = BDM.rand[Double](numExamples, numClasses)
    val y = BDM.zeros[Double](numExamples, numClasses)

    val startTime = System.nanoTime()

    softmax.eval(x,y)

    val stopTime = System.nanoTime()

    stopTime - startTime
  }
  val avgTime = (times.reduce(_ + _).toDouble / times.size) * 1e-6

  println(s"numExamples: $numExamples, numClasses: $numClasses, avgTime: $avgTime ms")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment