Skip to content

Instantly share code, notes, and snippets.

@yu-iskw
Last active August 29, 2015 14:05
Show Gist options
  • Save yu-iskw/518a48a68ef368998058 to your computer and use it in GitHub Desktop.
Save yu-iskw/518a48a68ef368998058 to your computer and use it in GitHub Desktop.
Experiment the performance Math.abs() and breeze.numerics.abs

Source Code by scalatest

class CheckPerformanceSuite extends FunSuite {
  test("check the performance") {
    var start = System.currentTimeMillis()
    val vectors = (1 to 3000000).map { i => Vectors.dense(Math.random(), -1 * Math.random(), Math.random())}
    var end = System.currentTimeMillis()
    println(s"Time for Creating: ${end - start}")

    start = System.currentTimeMillis()
    vectors.map(v => v.toBreeze.map(x => abs(x)))
    end = System.currentTimeMillis()
    println(s"Time for mapping breeze.numerics.abs: ${end - start}")

    start = System.currentTimeMillis()
    vectors.map(v => v.toBreeze.map(x => Math.abs(x)))
    end = System.currentTimeMillis()
    println(s"Time for mapping Math.abs: ${end - start}")
  }
}

Result

Time for Creating: 2049
Time for mapping breeze.numerics.abs: 4025
Time for mapping Math.abs: 2561
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment