Hi,
Another microbenchmark i’ve done :
class HeavyTask implements Runnable {
// 10 millis task at least, crunching floats and arrays
}
after heating up hotspot server , processed 10 times this task using :
- a direct loop with a call to the run() method
- ThreadPoolExecutor (java.util.concurrent) with 2 threads or more.
results :
on my P4 with HT : 10 HeavyTask are executed between 120% and 200% faster than single threaded model depending of the type of computations.
on my old P3, from 80% to 110 % of the single threaded.
some thoughts :
It would be nice to take this extra power in OpenGL applications (with respect to its single threaded model), may be by writing something like that :
ExecutorService exec = Executors.newFixedThreadPool(2);
…
Callable callable1 = …// a heavy non gl task that returns a result for opengl
Callable callable2 = …// another task
Future f1 = exec.submit(callable1);
Future f2 = exec.submit(callable2);
// now inject results in opengl
Object computed1 = f1.get();
someGLProcessing(computed1); // callable2 in running in parallel
Object computed2 = f2.get();
anotherGLProcessing(computed2);
We could wrap up this method in a utility package to provide compatibility with non HT/multicore processors.
Wouldn’t it be nice if we could double the speed of non-gl work ? I am sure more and more time will be spent on the CPU (AI, ODE, …).
Any comments ?
Lilian

But we all know that two threads are better than one if you’ve got two CPUs - the question is, is it worth it?
The only guaranteed thing that will happen is that your code will become rather more complicated and the number of actual systems with SMT or SMP boards is going to be a relatively small number for some time to come. And of course there’s the small issue that most of us can’t even max the CPU out anyway as they’re so fast these days; the bottleneck is still the graphics card.