class ThreadTestB { static int s; public static void main(String[] args) { int numberofthreads = 100, numberofloops = 800; double min = 2000000000, max =0, speedup, timeused; long timestart, timeend, timeavg = 0; System.out.println("Starting " + numberofthreads + " threads" + "Looping " + numberofloops + " times"); for (int i = 0; i < numberofloops; i++) { timestart = System.nanoTime(); Thread[] t = new Thread[numberofthreads]; for (int j = 0; j < numberofthreads; j++) { (t[j] = new Thread(new ExThread())).start(); } try{ for (int k = 0;k< numberofthreads;k++) t[k].join(); }catch (Exception e) { return;} //System.out.println("Finished " + numberofthreads + " threads"); timeend = System.nanoTime(); timeused = ((timeend - timestart)/(1000.0*numberofthreads)); if (min > timeused) min = timeused; if (max < timeused) max = timeused; timeavg += timeused; System.out.println("Loop #" + (i+1) + " : " + ((timeend - timestart)/(1000.0*numberofthreads) )+ " us"); } timeavg = (timeavg / numberofloops); System.out.println("\nAverage time: " + timeavg + " us, max:"+max+", min:"+min+", speedup:"+ (max/min)); } } class ExThread implements Runnable { public void run() { String name = Thread.currentThread().getName(); try { ThreadTestB.s++; }catch (Exception e) { return;} } }