Skip to content

Instantly share code, notes, and snippets.

@squito
Last active December 18, 2015 17:39
Show Gist options
  • Save squito/5820049 to your computer and use it in GitHub Desktop.
Save squito/5820049 to your computer and use it in GitHub Desktop.
val n = 1e7.toInt
val (rawArray, rawBB, rawFloatBuf) = initArrays(n)
println("result = " + th.pbench({
var idx = 0
var sum = 0f
while(idx < n) {
sum += rawArray(idx)
idx += 1
}
sum
}, title="raw arrays"))
println("result = " + th.pbench({
var idx = 0
var sum = 0f
while(idx < n) {
sum += rawBB.getFloat(idx * 4)
idx += 1
}
sum
}, title="byte buffer"))
println("result = " + th.pbench({
var idx = 0
var sum = 0f
while(idx < n) {
sum += rawFloatBuf.get(idx)
idx += 1
}
sum
}, title="float buffer"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment