Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.