1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
7 import org.ibex.nestedvm.Runtime;
13 private static long start,end;
14 private static long now() { return System.currentTimeMillis(); }
15 private static void start() { start = now(); }
16 private static void end() { end = now(); }
17 private static float diff() { return ((float)(end-start))/1000; }
19 /*private static InputStream is = new InputStream() {
20 int left = 100*1024*1024;
22 public int read() { if(left==0) return -1; left--; return (c++)&0xff; }
23 public int read(byte[] buf, int pos,int len) {
24 len = Math.min(left,len);
25 Arrays.fill(buf,pos,len,(byte)c++);
29 public void close() { left = 100*1024*1024; }
32 private static OutputStream os = new OutputStream() {
33 public void write(int c) { }
34 public void write(byte[] buf, int pos, int len) { }
37 public static void main(String[] args) throws Exception {
40 if(args.length < 2) { System.err.println("Usage: SpeedTest {classname|mips binary} number_of_runs args"); System.exit(1); }
41 String className = args[0];
42 int runs = Integer.parseInt(args[1]);
43 if(runs < 5) throw new Error("Runs must be >= 5");
44 String[] appArgs = new String[args.length-1];
45 appArgs[0] = className;
46 for(int i=2;i<args.length;i++) appArgs[i-1] = args[i];
49 boolean binary = className.endsWith(".mips");
52 c = Class.forName(className);
55 System.out.println("Class.forName() took " + d + "sec");
61 System.out.println("c.newInstance() took " + d + "sec");
63 if(!Runtime.class.isAssignableFrom(c)) { System.err.println(className + " isn't a MIPS compiled class"); System.exit(1); }
65 throw new Error("Interpreter not supported in speedtest");
68 float times[] = new float[runs];
70 for(int i=0;i<runs;i++) {
71 //Runtime runtime = binary ? new Interpreter(className) : (Runtime) c.newInstance();
72 Runtime runtime = (Runtime) c.newInstance();
75 runtime.addFD(new Runtime.InputStreamFD(is));
76 runtime.addFD(new Runtime.OutputStreamFD(os));*/
79 int status = runtime.run(appArgs);
80 if(status != 0) { System.err.println(className + " failed with exit status: " + status); System.exit(1); }
84 System.err.println("Run " + (i+1) + ": " + times[i] + " sec");
87 java.util.Arrays.sort(times);
89 System.out.println("Best: " + times[0]);
90 System.out.println("Worst: " + times[times.length-1]);
92 for(int i=2;i<times.length-2;i++)
94 float avg = sum / (times.length-4);
95 System.out.println("Avg of middle " + (times.length-4) + ": " + avg);