Skip to content

Instantly share code, notes, and snippets.

@kutchar
Created March 16, 2015 07:06
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 kutchar/82ad7463146d7b4886b9 to your computer and use it in GitHub Desktop.
Save kutchar/82ad7463146d7b4886b9 to your computer and use it in GitHub Desktop.
JsNumber Tests
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