Index: src/tests/ThreadSim.java =================================================================== --- src/tests/ThreadSim.java (revision 0) +++ src/tests/ThreadSim.java (revision 0) @@ -0,0 +1,93 @@ +class Small +{ + private int i, j; +}; + +class MyThread extends Thread +{ + int tableSize; + int iterations; + + public MyThread(int _tableSize, int _iterations) + { + tableSize = _tableSize; + iterations = _iterations; + } + + public void run() + { + Small[] table = new Small[tableSize]; + + int iter = 0; + while (iter < iterations) + { + for (int i = 0; i < table.length; i++) + { + table[i] = new Small(); + iter++; + } + } + } +}; + +public class ThreadSim +{ + public static void test(int threadCount, int tableSize, int iterations) + { + MyThread t; + + System.out.println("Timing " + threadCount + " threads, retaining " + tableSize*threadCount + " Objects: " ); + + long start = System.currentTimeMillis(); + + MyThread[] threads = new MyThread[threadCount]; + + + for (int i = 0; i < threadCount; i++) + { + + threads[i] = new MyThread(tableSize, iterations); + threads[i].start(); + } + + try{ + for (int i = 0; i < threadCount; i++) + { + threads[i].join(); + } + } + catch(Exception e) + {} + + + double elapsedSeconds = (System.currentTimeMillis() - start)/1000.0; + int smallSize = 16; + long allocatedMegaBytes = (long)iterations*threadCount*smallSize/(1024*1024); + + System.out.println(elapsedSeconds + " seconds " + allocatedMegaBytes/elapsedSeconds + " MB/sec"); + } + + public static void main (String[] args) + { + int iter = 50*1000*1000; + + if (args.length >= 1) + iter = Integer.parseInt(args[0]); + + System.out.println("Timing " + iter/(1000*1000) + " million total object allocations"); + System.out.println("Varying number of threads and number of objects retained"); + System.out.println(); + + long start = System.currentTimeMillis(); + + for (int threadCount = 1; threadCount <= 32; threadCount *= 2) + { + for (int tableSize = 64; tableSize <= 8192; tableSize *= 2) + { + test(threadCount, tableSize/threadCount, iter/threadCount); + } + } + + System.out.println("Total: " + (System.currentTimeMillis() - start)/1000.0 + " seconds"); + } +}