Last active
December 18, 2015 17:39
-
-
Save squito/5820049 to your computer and use it in GitHub Desktop.
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
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
Gist for a blog post: http://imranrashid.com/posts/profiling-bytebuffers/
Full code is at https://github.com/squito/oleander/blob/blog_post_profiling_interfaces/src/test/scala/com/imranrashid/oleander/ByteBufferBackedTest.scala