Commit latest version
[lttng-ust-java-tests.git] / src / org / lttng / ust / tests / Benchmark.java
1 package org.lttng.ust.tests;
2
3 import java.io.IOException;
4 import java.util.logging.FileHandler;
5 import java.util.logging.Handler;
6 import java.util.logging.Level;
7 import java.util.logging.Logger;
8 import java.util.logging.SimpleFormatter;
9
10 import org.lttng.ust.LTTngUst;
11
12 public class Benchmark {
13
14 /** Nb of runs per test, result will be averaged */
15 private static final int NB_RUNS = 5;
16
17 /** Trace/log events per run */
18 private static final int NB_ITER = 1000000;
19
20 /** Which tests to run (for different number of threads) */
21 private static final int[] nbThreads = {1, 1, 2, 3, 4, 5, 6, 7, 8};
22
23 private static Runner runner;
24 private static Logger log;
25
26 public static void main(String[] args) throws SecurityException, IOException {
27
28 final Handler fh;
29
30 /* Set up the logger */
31 log = Logger.getLogger("Test logger");
32 log.setUseParentHandlers(false);
33 fh = new FileHandler("/tmp/log", false);
34 fh.setFormatter(new SimpleFormatter());
35 // log.addHandler(fh);
36 log.setLevel(Level.ALL);
37
38 /* Set up the tracer */
39 LTTngUst.init();
40 System.out.println("Press a key to start.");
41 System.in.read();
42
43 for (int i : nbThreads) {
44 runTest(i);
45 }
46 }
47
48
49 private static void runTest(int nbThreads) throws SecurityException, IOException {
50 long start, end, average, total = 0;
51 for (int i = 0; i < NB_RUNS; i++) {
52 runner = new Runner(nbThreads, NB_ITER, log);
53
54 start = System.nanoTime();
55 runner.run();
56 end = System.nanoTime();
57
58 total += (end - start);
59 }
60 average = total / NB_RUNS;
61 System.out.println(nbThreads + " threads, average = " + average / NB_ITER + " ns/event");
62 }
63 }
This page took 0.029423 seconds and 4 git commands to generate.