Last active
August 29, 2015 14:05
-
-
Save erikerlandson/488275019e4b54f5cdaf to your computer and use it in GitHub Desktop.
test performance of breeze abs(v) vs v.map(Math.abs(_))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import breeze.linalg.{Vector => BV, DenseVector => DBV} | |
import breeze.numerics.abs | |
def absTest(n: Int = 1000, m: Int = 10) { | |
var start = System.currentTimeMillis() | |
val vectors = (1 to n).toArray.map(i => DBV((1 to m).toArray.map(j => -1.0 + (2.0 * Math.random())))) | |
var end = System.currentTimeMillis() | |
println(s"Time for Creating: ${end - start}") | |
start = System.currentTimeMillis() | |
vectors.map(v => abs(v)) | |
end = System.currentTimeMillis() | |
println(s"Time for mapping breeze.numerics.abs: ${end - start}") | |
start = System.currentTimeMillis() | |
vectors.map(v => v.map(x => Math.abs(x))) | |
end = System.currentTimeMillis() | |
println(s"Time for mapping Math.abs: ${end - start}") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> absTest(n = 1000000, m = 10) | |
Time for Creating: 1471 | |
Time for mapping breeze.numerics.abs: 622 | |
Time for mapping Math.abs: 1255 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment