JMH Thread index?

Nitsan Wakart nitsanw at yahoo.com
Mon May 6 11:10:59 PDT 2013


Right... I know that...
What I meant was programmatically... in my benchmark code I have an array which is the benchmark state with an element per thread, I'd like to know the number of threads so I can allocate for the number of threads. Similarly, each thread needs to access it's own element, so I'd like to have a thread index which correlates to the thread stats reported in the output. The benchmark in question is here: https://github.com/nitsanw/jmh-samples/blob/master/src/main/java/psy/lob/saw/conc/FalseSharingBenchmarkPlain.java
I can live without it, but it would be handy. I can also have a terrible hack in place where I use the thread name to do this, but it might make me puke...


________________________________
 From: Aleksey Shipilev <aleksey.shipilev at oracle.com>
To: Nitsan Wakart <nitsanw at yahoo.com> 
Cc: JMH Dev <jmh-dev at openjdk.java.net> 
Sent: Monday, May 6, 2013 11:41 AM
Subject: Re: JMH Thread index?
 

On 05/04/2013 11:36 PM, Nitsan Wakart wrote:
> Hi, Doing a writeup on using JMH for writing multi-threaded
> benchmarks. It would be very useful for my benchmark/reporting if I
> could tell in my benchmark what is the thread index and how many
> threads are participating in this run/group.

I'm not sure what thread index is, but JMH sure does show how many
threads are participating in each group. See the sample output:

$ java -jar target/microbenchmarks.jar ".*JMHSample_15_Asymmetric.*"
# Measurement Section
# Runtime (per iteration): 5s
# Iterations: 20
# Thread counts (concurrent threads per iteration): [4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
# Threads will synchronize iterations
# Running:
org.openjdk.jmh.samples.generated.avgtime.JMHSample_15_Asymmetric.g
Iteration   1 (5s in 4 threads): get{t=1} = 12.137, inc{t=3} = 207.697
nsec/op

You can see there are:
  * 4 threads total
  * get() is executed with 1 thread
  * inc() is executed with 3 threads

-Aleksey.


More information about the jmh-dev mailing list