3 import org.xwt.mips.Runtime;
4 import org.xwt.mips.Interpreter;
7 private static long start,end;
8 private static long now() { return System.currentTimeMillis(); }
9 private static void start() { start = now(); }
10 private static void end() { end = now(); }
11 private static float diff() { return ((float)(end-start))/1000; }
13 public static void main(String[] args) throws Exception {
16 if(args.length < 2) { System.err.println("Usage: SpeedTest {classname|mips binary} number_of_runs args"); System.exit(1); }
17 String className = args[0];
18 int runs = Integer.parseInt(args[1]);
19 if(runs < 3) throw new Error("Runs must be >= 3");
20 String[] appArgs = new String[args.length-1];
21 appArgs[0] = className;
22 for(int i=2;i<args.length;i++) appArgs[i-1] = args[i];
25 boolean binary = className.endsWith(".mips");
28 c = Class.forName(className);
31 System.out.println("Class.forName() took " + d + "sec");
37 System.out.println("c.newInstance() took " + d + "sec");
39 if(!Runtime.class.isAssignableFrom(c)) { System.err.println(className + " isn't a MIPS compiled class"); System.exit(1); }
42 float times[] = new float[runs];
44 for(int i=0;i<runs;i++) {
45 Runtime runtime = binary ? new Interpreter(className) : (Runtime) c.newInstance();
48 int status = runtime.run(appArgs);
49 if(status != 0) { System.err.println(className + " failed with exit status: " + status); System.exit(1); }
56 for(int i=0;i<runs;i++) {
57 System.out.println("Run " + (i+1) + ": " + times[i] + " sec");
58 if(times[i] < times[best]) best = i;
59 if(times[i] > times[worst]) worst = i;
62 for(int i=0;i<runs;i++) if(i!=best && i!=worst) avg += times[i];
65 System.out.println("Best: " + times[best]);
66 System.out.println("Worst: " + times[worst]);
67 System.out.println("Avg of remaining " + (runs-2) + ": " + avg);