Skip to content

Commit dcf80e1

Browse files
committed
Merge branch 'develop'
2 parents 8c48256 + 18d19c2 commit dcf80e1

17 files changed

+576
-1232
lines changed

README.md

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,90 @@
1-
wargame
2-
=======
1+
WarGame Java
2+
============
33

4-
A kinda-sorta benchmarking program in Java.
4+
This is an updated version of the longstanding WarGame project from [@ryanmr](http://twitter/ryanmr), the kinda-sorta benchmark.
5+
6+
**Disclaimer:** WarGame Java is a tiny kinda-sorta benchmark, and as such, it should not be taken too seriously.
7+
8+
Changelog
9+
---------
10+
11+
Unfortunately, time has erased the progress of this project. Hopefully this brief explanation can fill in that gap.
12+
13+
It is worth noting that the original implementation of the WarGame was written in Java, while [@ryanmr](http://twitter.com/ryanmr) was a sophomore in high school, and every so often, he would revisit the project and expand on the progress.
14+
15+
In a sense this is the 4th major version:
16+
17+
1. Initial version written sometime in an air conditioned basement in 2009, designed to simply iterate to 1 million games.
18+
2. The *variation* approach was implemented, where the game would continue for *speed seconds* until the speed did not change within 4 decimal places
19+
3. A minor update to the second version, where the Java was Java-ized to be *pragmatic Java*, by which I mean, disgusting.
20+
4. A major update to mirror support the Rust and Go versions, now implementing the standardized prime and sample time approaches.
21+
22+
Legend
23+
------
24+
25+
You definitely should read the [legend](https://github.com/WarGameBenchmarks/wargame/blob/master/legend.md) to learn about the output.
26+
27+
How To Run
28+
----------
29+
30+
With the executable *JAR* directly:
31+
32+
```
33+
java -jar wargame-java.jar [number of threads] [multiplier]
34+
```
35+
36+
If the `number of threads` are not specified, the default is 1 thread. Specify the `multiplier` for additional run time according to the [legend](https://github.com/WarGameBenchmarks/wargame/blob/master/legend.md).
37+
38+
How To Compile
39+
--------------
40+
41+
To compile:
42+
43+
```
44+
./compile.sh
45+
```
46+
47+
To run likewise:
48+
49+
```
50+
./run.sh [number of threads] [multiplier]
51+
```
52+
53+
To bundle the class files into a jar, use the provided `bundle.sh` file:
54+
55+
```
56+
./bundle.sh
57+
```
58+
59+
Sample Output
60+
------
61+
62+
```
63+
➜ wargame-java ✗ java -jar wargame-java.jar
64+
WarGame Java
65+
settings: threads = 1; multiplier = 1.00
66+
67+
4. done
68+
---
69+
Samples: 9981
70+
Mean: 20.26894
71+
Median: 20.46168
72+
S.D.: 0.41262
73+
C.O.V.: 0.02036
74+
---
75+
Min-Max: < 18.96038 - 20.66101 > Δ 1.70063
76+
1-σ: < 19.85633 - 20.68156 > Δ 0.82523
77+
μ-Median: < 20.26894 - 20.46168 > Δ 0.19273
78+
99.9% CI: < 20.25535 - 20.28254 > Δ 0.02718
79+
---
80+
Threads: 1
81+
Multiplier: 1.00
82+
Speed: 20.49160 g/ms
83+
Games: 1229615
84+
Duration: 60.0s
85+
---
86+
Rank: (3/5) B
87+
Rank Criteria: 1 | 2 | 4
88+
---
89+
Score: 20
90+
```

bundle.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
jar cmf manifest.txt wargame-java.jar -C bin/ .

manifest.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Main-Class: wargame/App

run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
cd ${0%/*}
2-
java -cp "bin" wargame/App
2+
java -cp "bin" wargame/App $@

source/wargame/App.java

Lines changed: 18 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -4,159 +4,31 @@
44

55
class App {
66

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-
157
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() {
428

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;
4724
}
4825

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);
11127

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();
12129

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);
14831

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();
15832
}
15933

16034
}
161-
162-

0 commit comments

Comments
 (0)