This file contains 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
// https://mvnrepository.com/artifact/com.databasesandlife/java-common/8.8.0 | |
import com.databasesandlife.util.Timer; | |
import java.util.ArrayList; | |
import java.util.Random; | |
public class ThreadTimer { | |
public void main(String[] args) throws Exception { | |
for (int maxCores = 1; maxCores < 50; maxCores++) { | |
try (var ignored = new Timer(maxCores + " threads")) { | |
var threads = new ArrayList<Thread>(); | |
for (int core = 0; core < maxCores; core++) { | |
threads.add(new Thread(() -> { | |
var random = new Random(); | |
for (int work = 0; work < 100_000_000; work++) | |
random.nextInt(); | |
})); | |
} | |
for (var t : threads) t.start(); | |
for (var t : threads) t.join(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment