Last active
December 18, 2015 17:39
-
-
Save squito/5820134 to your computer and use it in GitHub Desktop.
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
trait ArrayLike[@specialized T] { | |
def apply(idx: Int) : T | |
def update(idx: Int, value: T) | |
def length: Int | |
def size: Int = length | |
} | |
def sumArrayLike(arr: ArrayLike[Float]): Float = { | |
var idx = 0 | |
var sum = 0f | |
while(idx < arr.length) { | |
sum += arr(idx) | |
idx += 1 | |
} | |
sum | |
} | |
val n = 1e7.toInt | |
val (_, wrapped, buf, arrBuf) = initArrays(n) // now this returns classes that implement ArrayLike | |
println("result = " + th.pbench(sumArrayLike(wrapped), title="wrapped array")) | |
println("result = " + th.pbench(sumArrayLike(arrBuf), title="float array wrapped in FloatBuffer")) | |
println("result = " + th.pbench(sumArrayLike(buf), title="byte array wrapped in FloatBuffer")) |
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