// field access performance tester, Dan Bonachea import java.util.Random; public class fieldperf { public static single void report(String desc, Timer t, int iters) { Ti.barrier(); if (Ti.thisProc() == 0) System.out.println(desc + ": " + t.micros()/iters*1000.0 + " ns per iteration (" + t.secs() + " secs total)"); Ti.barrier(); } #define TEST(msg, code) do { \ t.reset(); \ t.start(); \ for (int i=0; i < iters; i++) { \ code; \ } \ t.stop(); \ report(msg, t, iters); \ } while (false) public static single void main(String[]args) { int iters0 = 1000000; if (args.length > 0) try { iters0 = Integer.parseInt(args[0]); } catch (Throwable exn) {} int single iters = broadcast iters0 from 0; if (Ti.thisProc()==0) System.out.println("Running " + iters + " iterations of Random performance test on " + Ti.numProcs() + " threads"); Timer t = new Timer(); Random r = new Random(); int x; if (Ti.thisProc() == 0) System.out.println("--------------------------------------"); Ti.barrier(); TEST("Random.nextDouble()", r.nextDouble(); ); TEST("Random.nextInt()", r.nextInt(); ); } }