X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Forg%2Flttng%2Fust%2Ftests%2FBenchmark.java;h=b435e40fbfa514105414bc59bd780d69c888bb33;hb=7489e9d74a361d8b4d2f0c90cee8ad9dac9a365c;hp=45000ac944db833780b7f081b26434ab46a2566f;hpb=087a198a52ae532088b9222e3932cde17be58958;p=lttng-ust-java-tests.git diff --git a/src/org/lttng/ust/tests/Benchmark.java b/src/org/lttng/ust/tests/Benchmark.java index 45000ac..b435e40 100644 --- a/src/org/lttng/ust/tests/Benchmark.java +++ b/src/org/lttng/ust/tests/Benchmark.java @@ -2,6 +2,7 @@ package org.lttng.ust.tests; import java.io.IOException; import java.util.logging.FileHandler; +import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; import java.util.logging.SimpleFormatter; @@ -10,28 +11,28 @@ import org.lttng.ust.LTTngUst; public class Benchmark { + /** Nb of runs per test, result will be averaged */ private static final int NB_RUNS = 5; - private static final int NB_THREADS = 2; - - /** - * @param args - * @throws IOException - * @throws SecurityException - */ - public static void main(String[] args) throws SecurityException, - IOException { - Runner runner; - long start, end, average, total = 0; - final Logger log; - final FileHandler fh; + /** Trace/log events per run */ + private static final int NB_ITER = 1000000; + + /** Which tests to run (for different number of threads) */ + private static final int[] nbThreads = {1, 1, 2, 3, 4, 5, 6, 7, 8}; + + private static Runner runner; + private static Logger log; + + public static void main(String[] args) throws SecurityException, IOException { + + final Handler fh; /* Set up the logger */ log = Logger.getLogger("Test logger"); log.setUseParentHandlers(false); fh = new FileHandler("/tmp/log", false); fh.setFormatter(new SimpleFormatter()); - // log.addHandler(fh); +// log.addHandler(fh); log.setLevel(Level.ALL); /* Set up the tracer */ @@ -39,8 +40,16 @@ public class Benchmark { System.out.println("Press a key to start."); System.in.read(); + for (int i : nbThreads) { + runTest(i); + } + } + + + private static void runTest(int nbThreads) throws SecurityException, IOException { + long start, end, average, total = 0; for (int i = 0; i < NB_RUNS; i++) { - runner = new Runner(NB_THREADS, log); + runner = new Runner(nbThreads, NB_ITER, log); start = System.nanoTime(); runner.run(); @@ -49,7 +58,6 @@ public class Benchmark { total += (end - start); } average = total / NB_RUNS; - System.out.println("Average = " + average / 1000000 + " ms"); + System.out.println(nbThreads + " threads, average = " + average / NB_ITER + " ns/event"); } - }