3 import org.ibex.nestedvm.Runtime;
9 private static long start,end;
10 private static long now() { return System.currentTimeMillis(); }
11 private static void start() { start = now(); }
12 private static void end() { end = now(); }
13 private static float diff() { return ((float)(end-start))/1000; }
15 /*private static InputStream is = new InputStream() {
16 int left = 100*1024*1024;
18 public int read() { if(left==0) return -1; left--; return (c++)&0xff; }
19 public int read(byte[] buf, int pos,int len) {
20 len = Math.min(left,len);
21 Arrays.fill(buf,pos,len,(byte)c++);
25 public void close() { left = 100*1024*1024; }
28 private static OutputStream os = new OutputStream() {
29 public void write(int c) { }
30 public void write(byte[] buf, int pos, int len) { }
33 public static void main(String[] args) throws Exception {
36 if(args.length < 2) { System.err.println("Usage: SpeedTest {classname|mips binary} number_of_runs args"); System.exit(1); }
37 String className = args[0];
38 int runs = Integer.parseInt(args[1]);
39 if(runs < 5) throw new Error("Runs must be >= 5");
40 String[] appArgs = new String[args.length-1];
41 appArgs[0] = className;
42 for(int i=2;i<args.length;i++) appArgs[i-1] = args[i];
45 boolean binary = className.endsWith(".mips");
48 c = Class.forName(className);
51 System.out.println("Class.forName() took " + d + "sec");
57 System.out.println("c.newInstance() took " + d + "sec");
59 if(!Runtime.class.isAssignableFrom(c)) { System.err.println(className + " isn't a MIPS compiled class"); System.exit(1); }
61 throw new Error("Interpreter not supported in speedtest");
64 float times[] = new float[runs];
66 for(int i=0;i<runs;i++) {
67 //Runtime runtime = binary ? new Interpreter(className) : (Runtime) c.newInstance();
68 Runtime runtime = (Runtime) c.newInstance();
71 runtime.addFD(new Runtime.InputStreamFD(is));
72 runtime.addFD(new Runtime.OutputStreamFD(os));*/
75 int status = runtime.run(appArgs);
76 if(status != 0) { System.err.println(className + " failed with exit status: " + status); System.exit(1); }
80 System.err.println("Run " + (i+1) + ": " + times[i] + " sec");
83 java.util.Arrays.sort(times);
85 System.out.println("Best: " + times[0]);
86 System.out.println("Worst: " + times[times.length-1]);
88 for(int i=2;i<times.length-2;i++)
90 float avg = sum / (times.length-4);
91 System.out.println("Avg of middle " + (times.length-4) + ": " + avg);