Skip to content

Instantly share code, notes, and snippets.

@alextkachman
Created May 19, 2011 19:45
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 alextkachman/981566 to your computer and use it in GitHub Desktop.
Save alextkachman/981566 to your computer and use it in GitHub Desktop.
GPars-like BenchmarkStatelessActorWithArray
@Typed package p
import java.util.concurrent.Executors
import java.util.concurrent.CountDownLatch
import groovypp.channels.ExecutingChannel
import java.util.concurrent.TimeUnit
def pool = Executors.newFixedThreadPool(8)
def t1 = System.currentTimeMillis()
CountDownLatch cdl = [10000 * 500]
def channels = new ExecutingChannel[10000]
for (int i = 0; i < 10000; i++) {
channels[i] = [
executor: pool,
onMessage: { msg ->
if (i < channels.length - 1) channels[i + 1].post(msg)
cdl.countDown()
}
]
}
for (int i = 0; i < 500; i++) {
channels[i].post("Hi")
for (int j = 0; j < i; j++) {
cdl.countDown()
}
}
cdl.await(1000, TimeUnit.SECONDS)
pool.shutdown()
println(System.currentTimeMillis() - t1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment