public Integer call() { int l = System.identityHashCode(this); l = LoopHelpers.compute2(l); int s = LoopHelpers.compute1(l); l = LoopHelpers.compute2(l); s += LoopHelpers.compute1(l); return new Integer(s); }
public final Object call() throws Exception { barrier.await(); int sum = v; int x = 0; int n = ITERS; while (n-- > 0) { lock.lockInterruptibly(); try { v = x = LoopHelpers.compute1(v); } finally { lock.unlock(); } sum += LoopHelpers.compute2(LoopHelpers.compute2(x)); } return new Integer(sum); }
static void tests(Class mapClass, int numTests, int sizeIndex) { try { String[] key = readWords(sizeIndex); int size = key.length; System.out.print("n = " + LoopHelpers.rightJustify(size) + " : "); long least = Long.MAX_VALUE; for (int i = 0; i < numTests; ++i) { Map<String, String> m = newMap(mapClass); long t = doTest(i, mapClass.getName(), m, key); if (t < least) least = t; m.clear(); m = null; } long nano = Math.round(1000000.0 * (least) / NOPS); System.out.println(LoopHelpers.rightJustify(nano) + " ns per op"); } catch (IOException ignore) { return; // skip test if can't read file } }
static void oneTest(int iters) throws Exception { long startTime = System.nanoTime(); new Thread(new Producer(ecs, iters)).start(); int r = 0; for (int i = 0; i < iters; ++i) r += ecs.take().get().intValue(); long elapsed = System.nanoTime() - startTime; long tpi = elapsed / iters; if (print) System.out.println("\t: " + LoopHelpers.rightJustify(tpi) + " ns per task"); if (r == 0) // avoid overoptimization System.out.println("useless result: " + r); }
static void oneRun(BlockingQueue<Runnable> q, int nThreads, int iters, boolean print) throws Exception { ThreadPoolExecutor pool = new ThreadPoolExecutor(nThreads + 1, Integer.MAX_VALUE, 1L, TimeUnit.SECONDS, q); CountDownLatch done = new CountDownLatch(iters); remaining.set(nThreads - 1); pool.prestartAllCoreThreads(); Task t = new Task(pool, done); long start = System.nanoTime(); pool.execute(t); done.await(); long time = System.nanoTime() - start; if (print) System.out.println("\t: " + LoopHelpers.rightJustify(time / iters) + " ns per task"); q.clear(); Thread.sleep(100); pool.shutdown(); Thread.sleep(100); pool.shutdownNow(); }