Exemple #1
0
  public static void main(String[] args) throws Exception {
    // Warmup.
    char[] input = createInput(5);

    for (int i = 9999; i >= 0; --i) {
      LeftFactored lf = new LeftFactored(input);
      lf.parse("S");
    }

    // The benchmarks.
    for (int i = 50000; i <= 200000; i += 50000) {
      input = createInput(i);
      runTest(input);
    }
  }
Exemple #2
0
  private static void runTest(char[] input) throws Exception {
    ThreadMXBean tmxb = ManagementFactory.getThreadMXBean();

    long total = 0;
    long lowest = Long.MAX_VALUE;
    for (int i = ITERATIONS - 1; i >= 0; --i) {
      cleanup();

      long start = tmxb.getCurrentThreadCpuTime();
      LeftFactored lf = new LeftFactored(input);
      lf.parse("S");
      long end = tmxb.getCurrentThreadCpuTime();

      long time = (end - start) / 1000000;
      total += time;
      lowest = (time < lowest) ? time : lowest;
    }
    System.out.println(
        input.length + ": avg=" + (total / ITERATIONS) + "ms, lowest=" + lowest + "ms");
  }