Skip to content

Commit

Permalink
Set default number of threads based on number of cores
Browse files Browse the repository at this point in the history
Using more threads than cores results in unnecessary context switches and will actually decrease throughput. I set the number of threads to the number cores minus 1 so the OS has one core to do other pressing things and does not need to congest the cores utilized by JMH.
  • Loading branch information
sebthom authored Mar 2, 2024
1 parent 9066de4 commit 41a6a83
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/github/fabienrenaud/jjb/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public static abstract class AbstractCommand implements Runnable {
public int measurementIterations = 10;
@Option(type = OptionType.GLOBAL, name = "-m", description = "JMH: measurement time in seconds. Defaults to 3.")
public int measurementTime = 3;
@Option(type = OptionType.GLOBAL, name = "-t", description = "JMH: number of threads. Defaults to 16.")
public int threads = 16;
@Option(type = OptionType.GLOBAL, name = "-t", description = "JMH: number of threads. Defaults to number of cores-1.")
public int threads = Math.max(Runtime.getRuntime().availableProcessors() - 1, 1);

/*
* JSON options
Expand Down

0 comments on commit 41a6a83

Please sign in to comment.