import lava.clib.Stdio; import lava.clib.stdarg.Va_list; import lava.clib.stdio.Printf; import lava.clib.stdio.PrintfFormatString; import lava.string.StringToolbox; final class speeduptest { private static final int LOOP_REPEATS = 20; private static final int TRIALS = 10; public static void main (String[] args) { long[] times0 = new long [TRIALS]; long[] times1 = new long [TRIALS]; long[] times5 = new long [TRIALS]; for (int t = 0; t < TRIALS; ++ t) { times0 [t] = method0 (); times1 [t] = method1 (); times5 [t] = method5 (); } Stdio.fprintf ( System.err, "\n\n%10s%10s%10s\n", new Va_list () . add ("null") . add ("method1") . add ("method5") ); for (int t = 0; t < TRIALS; ++ t) Stdio.fprintf ( System.err, "%10ld%10ld%10ld\n", new Va_list () . add (times0 [t]) . add (times1 [t]) . add (times5 [t]) ); } private static String fmt0 = StringToolbox.repeat ('x', 40) + '\n'; private static String fmt1 = "%#10c%+10d%10.4o%#10.2x\n"; private static PrintfFormatString fmt5 = new PrintfFormatString (fmt1); private static long method0 () { long start = System.currentTimeMillis (); for (int j = 0; j < LOOP_REPEATS; ++ j) for (int i = 0; i < 256; ++ i) System.out . print (fmt0); long stop = System.currentTimeMillis (); return stop - start; } private static long method1 () { long start = System.currentTimeMillis (); for (int j = 0; j < LOOP_REPEATS; ++ j) for (int i = 0; i < 256; ++ i) Stdio.printf ( fmt1, new Va_list () . add ((char) i) . add (i) . add (i) . add (i) ); long stop = System.currentTimeMillis (); return stop - start; } private static long method5 () { long start = System.currentTimeMillis (); for (int j = 0; j < LOOP_REPEATS; ++ j) for (int n = 0; n < 256; ++ n) { Integer i = new Integer (n); System.out . println ( Printf.format ( fmt5, new Object[] { new Character ((char) n), i, i, i } ) ); } long stop = System.currentTimeMillis (); return stop - start; } }