Interesting Benchmarks

Ignaz Birnstingl ignazb at gmail.com
Wed Nov 10 20:16:11 UTC 2021


Hi Eric,

here are my thoughts:

Creating platform threads is an expensive operation. Your benchmarks show  
this very well. I would guess that starting a single platform thread costs  
somewhere between 10µs to 1ms. So spinning up platform threads that run  
for ~30ms before terminating means that at most 30000 platform threads  
would run in parallel. You could easily check that by using two  
AtomicIntegers in your isPrime() method: One keeps a count of currently  
running tasks. You increment it in the beginning of isPrime() and  
decrement it in the end of isPrime(). The other one would hold the maximum  
of the first one after incrementation. I would guess that the maximum of  
platform threads running in parallel is much lower than for virtual  
threads.

If you want to compare the throughput of the solutions it would probably  
make sense to pass in the ExecutorService you want to use to your  
futurePrimes22() method instead of creating it in there.
Then you could compare Executors.newCachedThreadPool() vs.  
Executors.newFixedThreadPool() (with different numbers) and  
Executors.newVirtualThreadExecutor().

Ignaz


More information about the loom-dev mailing list