MCPcopy Create free account
hub / github.com/ForOhForError/Yet-Another-Magic-Card-Recognizer / Benchmark

Class Benchmark

src/Benchmark.java:13–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11import java.util.Random;
12
13public class Benchmark {
14 interface IntWriter {
15 void write(int[] ints);
16 }
17
18 public static final int NUM_INTS = 1000000;
19 public static final int NUM_TESTS = 3;
20 public static final String[] TESTS = { "Buffered DataOutputStream", "DataOutputStream", "ObjectOutputStream",
21 "FileChannel alt" };
22
23 public static void main(String[] args) {
24 // create buffer
25 int[] ints = new int[NUM_INTS];
26 Random r = new Random();
27 for (int i = 0; i < NUM_INTS; i++)
28 ints[i] = r.nextInt();
29
30 // run tests
31 double[][] results = new double[TESTS.length][NUM_TESTS];
32
33 System.out.print("Running tests... ");
34 for (int i = 0; i < NUM_TESTS; i++) {
35 System.out.print(i + " ");
36
37 results[0][i] = time("Buffered DataOutputStream", new IntWriter() {
38 public void write(int[] ints) {
39 storeBDO(ints);
40 }
41 }, ints);
42
43 results[1][i] = time("DataOutputStream", new IntWriter() {
44 public void write(int[] ints) {
45 storeDO(ints);
46 }
47 }, ints);
48
49 results[2][i] = time("ObjectOutputStream", new IntWriter() {
50 public void write(int[] ints) {
51 storeOO(ints);
52 }
53 }, ints);
54
55 results[3][i] = time("FileChannel alt", new IntWriter() {
56 public void write(int[] ints) {
57 storeFCAlt(ints);
58 }
59 }, ints);
60 }
61 System.out.println();
62
63 // print results
64 for (int i = 0; i < TESTS.length; i++) {
65 System.out.print(TESTS[i] + "\t");
66 for (int j = 0; j < NUM_TESTS; j++) {
67 System.out.print(results[i][j] + "\t");
68 }
69 System.out.println();
70 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected