Created
May 19, 2011 19:45
-
-
Save alextkachman/981566 to your computer and use it in GitHub Desktop.
GPars-like BenchmarkStatelessActorWithArray
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
@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