1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
7 import java.lang.reflect.*;
9 class GenericSpeedTest {
10 private static long start,end;
11 private static long now() { return System.currentTimeMillis(); }
12 private static void start() { start = now(); }
13 private static void end() { end = now(); }
14 private static float diff() { return ((float)(end-start))/1000; }
16 public static void main(String[] args) throws Exception {
19 if(args.length < 2) { System.err.println("Usage: GenericSpeedTest runs classname args"); System.exit(1); }
20 int runs = Integer.parseInt(args[0]);
21 String className = args[1];
22 if(runs < 5) throw new Error("Runs must be >= 5");
23 String[] appArgs = new String[args.length-2];
24 for(int i=2;i<args.length;i++) appArgs[i-2] = args[i];
26 Class c = Class.forName(className);
27 Method m = c.getMethod("main",new Class[]{Class.forName("[Ljava.lang.String;")});
29 float times[] = new float[runs];
30 Object[] mainArgs = new Object[] { appArgs };
31 for(int i=0;i<runs;i++) {
34 m.invoke(null,mainArgs);
37 System.err.println("Run " + (i+1) + ": " + times[i] + " sec");
40 java.util.Arrays.sort(times);
42 System.out.println("Best: " + times[0]);
43 System.out.println("Worst: " + times[times.length-1]);
45 for(int i=2;i<times.length-2;i++)
47 float avg = sum / (times.length-4);
48 System.out.println("Avg of middle " + (times.length-4) + ": " + avg);