|
4 | 4 |
|
5 | 5 | class App { |
6 | 6 |
|
7 | | - public static final long ms = Benchmark.MS; |
8 | | - public static final long ns = Benchmark.NS; |
9 | | - public static final NumberFormat pf = NumberFormat.getPercentInstance(); |
10 | | - public static final NumberFormat df = NumberFormat.getInstance(); |
11 | | - public static final NumberFormat inf = NumberFormat.getIntegerInstance(); |
12 | | - |
13 | | - private static boolean interrupt = false; |
14 | | - |
15 | 7 | public static void main(String[] args) { |
16 | | - |
17 | | - print_header(); |
18 | | - |
19 | | - pf.setMaximumFractionDigits(2); |
20 | | - df.setMaximumFractionDigits(4); |
21 | | - df.setMinimumFractionDigits(4); |
22 | | - |
23 | | - |
24 | | - |
25 | | - BenchmarkSettings settings = handleArguments(args); |
26 | | - |
27 | | - print_settings(settings); |
28 | | - |
29 | | - final Benchmark benchmark = new Benchmark(settings); |
30 | | - BenchmarkPrinter printer = new BenchmarkPrinter(benchmark) { |
31 | | - public void print() { |
32 | | - String display_tail; |
33 | | - if ( this.getBenchmark().isTest_started() ) display_tail = "Test #" + this.getBenchmark().getTests() + " at " + inf.format( (this.getBenchmark().getTest_time() - this.getBenchmark().getElapsed_time()) / ns ) + " seconds"; |
34 | | - else display_tail = inf.format( (this.getBenchmark().getPrime_time() - this.getBenchmark().getElapsed_time()) / ns ) + " seconds left"; |
35 | | - |
36 | | - System.out.print("\r " + " Speed: " + df.format( (this.getBenchmark().getSpeed() * ms) ) + " (g/ms) - " + display_tail ); |
37 | | - } |
38 | | - }; |
39 | | - benchmark.attachPrinter(printer); |
40 | | - |
41 | | - Thread shutdown = new Thread() { |
42 | 8 |
|
43 | | - public void run() { |
44 | | - benchmark.end(); |
45 | | - System.out.println("\n\n\t--- Interrupt ---\n"); |
46 | | - interrupt = true; |
| 9 | + System.out.println("WarGame Java"); |
| 10 | + |
| 11 | + int threads = 1; |
| 12 | + double multiplier = 1.00; |
| 13 | + |
| 14 | + try { |
| 15 | + if (args.length >= 2) { |
| 16 | + multiplier = Double.parseDouble(args[1]); |
| 17 | + } |
| 18 | + if (args.length >= 1) { |
| 19 | + threads = Integer.parseInt(args[0]); |
| 20 | + } |
| 21 | + } catch (Exception e) { |
| 22 | + threads = 1; |
| 23 | + multiplier = 1.00; |
47 | 24 | } |
48 | 25 |
|
49 | | - }; |
50 | | - |
51 | | - Runtime.getRuntime().addShutdownHook(shutdown); |
52 | | - |
53 | | - benchmark.start(); |
54 | | - |
55 | | - if ( interrupt == false ) { |
56 | | - Runtime.getRuntime().removeShutdownHook(shutdown); |
57 | | - } |
58 | | - |
59 | | - print_results(benchmark); |
60 | | - |
61 | | - } |
62 | | - |
63 | | - public static BenchmarkSettings handleArguments(String[] args) { |
64 | | - boolean hasArguments = ( args.length > 0 ); |
65 | | - |
66 | | - BenchmarkSettings settings = new BenchmarkSettings(); |
67 | | - |
68 | | - |
69 | | - if ( hasArguments && args[0].equals("i") ) { |
70 | | - System.out.println( " --- Interactive Mode" ); |
71 | | - |
72 | | - SettingsSelector ss = new SettingsSelector(settings); |
73 | | - |
74 | | - ss.getThreads(); |
75 | | - ss.getPrimeTime(); |
76 | | - ss.getVariationMagnitude(); |
77 | | - ss.getMaximumTests(); |
78 | | - ss.getUpdateFrequency(); |
79 | | - |
80 | | - } else if ( hasArguments && args[0].equals("s") ) { |
81 | | - System.out.println( " --- Short Run Mode" ); |
82 | | - |
83 | | - settings.variation_magnitude(2).prime_time(10).update_frequency(30).maximum_tests(10); |
84 | | - |
85 | | - } else if ( hasArguments && (args[0].equals("h") || args[0].equals("help")) ) { |
86 | | - print_help(); |
87 | | - System.exit(1); |
88 | | - } |
89 | | - |
90 | | - return settings; |
91 | | - |
92 | | - |
93 | | - } |
94 | | - |
95 | | - public static void print_results(Benchmark benchmark) { |
96 | | - System.out.println(); |
97 | | - System.out.println( " Results:"); |
98 | | - System.out.println(); |
99 | | - |
100 | | - System.out.println( " Elapsed time: \n\t" + inf.format((benchmark.getEnd_time() - benchmark.getStart_time()) / ns) + " seconds \n\t~" + df.format((benchmark.getEnd_time() - benchmark.getStart_time()) / ms / 1000.0 / 60.0) + " minutes"); |
101 | | - System.out.println( " Games completed: \t" + inf.format( WarGameThread.getCompleted(benchmark.getThreads()) ) + " " ); |
102 | | - System.out.println( " Tests completed: \t" + inf.format( benchmark.getTests() ) + " " ); |
103 | | - |
104 | | - System.out.println(); |
105 | | - |
106 | | - System.out.println( " Speed improvement: " + pf.format( 1 - (benchmark.getPrime_speed() / benchmark.getSpeed()) ) + ""); |
107 | | - System.out.println( " from " + df.format(benchmark.getPrime_speed() * ms) + " (g/ms) to " + df.format(benchmark.getSpeed() * ms) + " (g/ms)"); |
108 | | - System.out.println( " Final confidence range:\n " + df.format(1/benchmark.getRate_low() * ms) + " (g/ms) > " + df.format(benchmark.getSpeed() * ms) + " (g/ms) > " + df.format(1/benchmark.getRate_high() * ms) + " (g/ms)" ); |
109 | | - |
110 | | - System.out.println(); |
| 26 | + System.out.printf("settings: threads = %d; multiplier = %.2f\n\n", threads, multiplier); |
111 | 27 |
|
112 | | - System.out.println( " Final rate: \t" + df.format( (benchmark.getRate() / ms) ) + " (ms/g)" ); |
113 | | - System.out.println( " Final speed: \t" + df.format( (benchmark.getSpeed() * ms) ) + " (g/ms)" ); |
114 | | - System.out.println(); |
115 | | - System.out.println( " Final score: \t" + inf.format( Math.round((benchmark.getSpeed() * ms)) ) + " " ); |
116 | | - |
117 | | - if ( interrupt == false ) { |
118 | | - System.out.println(); |
119 | | - System.out.println(" Submit results: \n\thttp://ifupdown.com/wg/results.php?fsc=" + inf.format( Math.round((benchmark.getSpeed() * ms)) ) + "&fsp=" + df.format( (benchmark.getSpeed() * ms) ) + "&tds=" + benchmark.getSettings().getAvailable_threads() + "&elt=" + inf.format((benchmark.getEnd_time() - benchmark.getStart_time()) / ns) + "&gcd=" + WarGameThread.getCompleted(benchmark.getThreads())); |
120 | | - } |
| 28 | + Benchmark benchmark = new Benchmark(); |
121 | 29 |
|
122 | | - System.out.println(); |
123 | | - } |
124 | | - |
125 | | - public static void print_help() { |
126 | | - System.out.println( " --- Help"); |
127 | | - System.out.println( " --- java App: runs with default settings"); |
128 | | - System.out.println( " --- java App s: runs a short test"); |
129 | | - System.out.println( " --- java App i: allows user to choose settings"); |
130 | | - System.out.println( " --- java App help: displays this information"); |
131 | | - System.out.println( " -- threads: defaults to the number of logical processors available"); |
132 | | - System.out.println( " -- variation magnitude: defaults to 4 e.g. 10^-4 or .0001, results will be +/- .01%"); |
133 | | - System.out.println( " -- prime time: the period to wait before beginning testing"); |
134 | | - System.out.println( " -- maximum tests: the maximum number of tests allowed per run"); |
135 | | - System.out.println( " -- update frequency: the number of times per second values update"); |
136 | | - System.out.println( " --- Visit http://ifupdown.com/wg for more information..."); |
137 | | - System.out.println(); |
138 | | - System.out.println(); |
139 | | -} |
140 | | - |
141 | | - public static void print_header() { |
142 | | - System.out.println(); |
143 | | - System.out.println( " ============================= " ); |
144 | | - System.out.println( " ======= WarGame 2.1 ======= " ); |
145 | | - System.out.println( " ============================= " ); |
146 | | - System.out.println(); |
147 | | - } |
| 30 | + benchmark.benchmark(threads, multiplier); |
148 | 31 |
|
149 | | - public static void print_settings(BenchmarkSettings settings) { |
150 | | - System.out.println(); |
151 | | - System.out.println( " Settings:"); |
152 | | - System.out.println( " Number of threads: " + settings.getAvailable_threads() ); |
153 | | - System.out.println( " Variation magnitude: " + settings.getVariation_magnitude() + " [" + pf.format(Math.pow(10, settings.getVariation_magnitude())) + "] " ); |
154 | | - System.out.println( " Prime time: " + settings.getPrime_time() + " seconds " ); |
155 | | - System.out.println( " Maximum tests: " + settings.getMaximum_tests() + " " ); |
156 | | - System.out.println( " Update frequency: " + settings.getUpdate_frequency() + " fps " ); |
157 | | - System.out.println(); |
158 | 32 | } |
159 | 33 |
|
160 | 34 | } |
161 | | - |
162 | | - |
0 commit comments