Commit latest version
[lttng-ust-java-tests.git] / src / org / lttng / ust / tests / Benchmark.java
CommitLineData
087a198a
AM
1package org.lttng.ust.tests;
2
3import java.io.IOException;
4import java.util.logging.FileHandler;
7489e9d7 5import java.util.logging.Handler;
087a198a
AM
6import java.util.logging.Level;
7import java.util.logging.Logger;
8import java.util.logging.SimpleFormatter;
9
10import org.lttng.ust.LTTngUst;
11
12public class Benchmark {
13
7489e9d7 14 /** Nb of runs per test, result will be averaged */
087a198a 15 private static final int NB_RUNS = 5;
087a198a 16
7489e9d7
AM
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;
087a198a
AM
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());
7489e9d7 35// log.addHandler(fh);
087a198a
AM
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
7489e9d7
AM
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;
087a198a 51 for (int i = 0; i < NB_RUNS; i++) {
7489e9d7 52 runner = new Runner(nbThreads, NB_ITER, log);
087a198a
AM
53
54 start = System.nanoTime();
55 runner.run();
56 end = System.nanoTime();
57
58 total += (end - start);
59 }
60 average = total / NB_RUNS;
7489e9d7 61 System.out.println(nbThreads + " threads, average = " + average / NB_ITER + " ns/event");
087a198a 62 }
087a198a 63}
This page took 0.03269 seconds and 4 git commands to generate.