3 import org.ibex.nestedvm.Runtime;
6 private static long start,end;
7 private static long now() { return System.currentTimeMillis(); }
8 private static void start() { start = now(); }
9 private static void end() { end = now(); }
10 private static float diff() { return ((float)(end-start))/1000; }
12 public static void main(String[] args) throws Exception {
15 if(args.length < 2) { System.err.println("Usage: SpeedTest {classname|mips binary} number_of_runs args"); System.exit(1); }
16 String className = args[0];
17 int runs = Integer.parseInt(args[1]);
18 if(runs < 5) throw new Error("Runs must be >= 5");
19 String[] appArgs = new String[args.length-1];
20 appArgs[0] = className;
21 for(int i=2;i<args.length;i++) appArgs[i-1] = args[i];
24 boolean binary = className.endsWith(".mips");
27 c = Class.forName(className);
30 System.out.println("Class.forName() took " + d + "sec");
36 System.out.println("c.newInstance() took " + d + "sec");
38 if(!Runtime.class.isAssignableFrom(c)) { System.err.println(className + " isn't a MIPS compiled class"); System.exit(1); }
40 throw new Error("Interpreter not supported in speedtest");
43 float times[] = new float[runs];
45 for(int i=0;i<runs;i++) {
46 //Runtime runtime = binary ? new Interpreter(className) : (Runtime) c.newInstance();
47 Runtime runtime = (Runtime) c.newInstance();
50 int status = runtime.run(appArgs);
51 if(status != 0) { System.err.println(className + " failed with exit status: " + status); System.exit(1); }
54 System.err.println("Run " + (i+1) + ": " + times[i] + " sec");
57 java.util.Arrays.sort(times);
59 System.out.println("Best: " + times[0]);
60 System.out.println("Worst: " + times[times.length-1]);
62 for(int i=2;i<times.length-2;i++)
64 float avg = sum / (times.length-4);
65 System.out.println("Avg of middle " + (times.length-4) + ": " + avg);