Created
March 16, 2015 07:06
-
-
Save kutchar/82ad7463146d7b4886b9 to your computer and use it in GitHub Desktop.
JsNumber Tests
This file contains 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
case class JsNumber(i: Number) | |
case class JsBigDecimal(i: BigDecimal) | |
object Test extends App { | |
val count = 1000000 | |
//============================================= | |
//JsNumber | |
//============================================= | |
//With Int, 42ms | |
{ | |
var i: Int = 0 | |
var start = System.currentTimeMillis | |
i = 0 | |
while (i < count) { JsNumber(i); i += 1 } | |
println(System.currentTimeMillis - start) | |
} | |
//With Double, 22ms | |
{ | |
var i: Double = 0 | |
var start = System.currentTimeMillis | |
i = 0 | |
while (i < count) { JsNumber(i); i += 1 } | |
println(System.currentTimeMillis - start) | |
} | |
//With Long, 22ms | |
{ | |
var i: Long = 0 | |
var start = System.currentTimeMillis | |
i = 0 | |
while (i < count) { JsNumber(i); i += 1 } | |
println(System.currentTimeMillis - start) | |
} | |
//============================================= | |
//JsBigDecimal | |
//============================================= | |
//With Int, 73ms | |
{ | |
var i: Int = 0 | |
var start = System.currentTimeMillis | |
i = 0 | |
while (i < count) { JsBigDecimal(i); i += 1 } | |
println(System.currentTimeMillis - start) | |
} | |
//With Double, 270ms | |
{ | |
var i: Double = 0 | |
var start = System.currentTimeMillis | |
i = 0 | |
while (i < count) { JsBigDecimal(i); i += 1 } | |
println(System.currentTimeMillis - start) | |
} | |
//With Long, 41ms | |
{ | |
var i: Long = 0 | |
var start = System.currentTimeMillis | |
i = 0 | |
while (i < count) { JsBigDecimal(i); i += 1 } | |
println(System.currentTimeMillis - start) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment