Skip to content

Instantly share code, notes, and snippets.

@boggle
Created February 6, 2013 23:01
Show Gist options
  • Save boggle/4726703 to your computer and use it in GitHub Desktop.
Save boggle/4726703 to your computer and use it in GitHub Desktop.
package org.neo4j.cypher.performance
import org.junit.Test
class ScalaStreamTest {
@Test def stream_append_should_use_linear_memory() {
def streamAppendTimes(times: Int): Float =
{
var stream = Stream(0,1,2,3,4,5,6,7,8,9)
System.gc()
val before = Runtime.getRuntime.freeMemory();
for ( i <- 1.to(times) )
{
stream = stream :+ i
}
val after = Runtime.getRuntime.freeMemory();
System.gc()
(before - after) / times
}
streamAppendTimes(100000)
streamAppendTimes(100000)
streamAppendTimes(100000)
val nums = 1.to(10).map { (i: Int) => streamAppendTimes(i * 25000) }
println(nums)
val rest = nums.zip(nums.tail :+ 0.asInstanceOf[Float]).reverse.tail.reverse
println(rest)
val diff = rest.map { (p: (Float, Float)) => Math.abs((p._2 - p._1)) / p._1 }
println(diff)
assert(diff.forall( _ < 0.5))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment