@Test public void test() throws Exception { benchmark.doSomething("string-->int:", () -> Integer.parseInt("1")); benchmark.doSomething("int-->string:", () -> String.valueOf(1)); }
public void doSomething(String name, BenchmarkCallback callback) throws Exception { for (int i = 0; i < PREHEATING_TIMES; i++) { callback.doSomething(); } long start = System.nanoTime(); for (int i = 0; i < times; i++) { callback.doSomething(); } long end = System.nanoTime(); System.out.println(name + "\t" + (end - start) / 100_0000f + " ms"); }
Benchmark { public void doSomething(String name, BenchmarkCallback callback) throws Exception { for (int i = 0; i < PREHEATING_TIMES; i++) { callback.doSomething(); } long start = System.nanoTime(); for (int i = 0; i < times; i++) { callback.doSomething(); } long end = System.nanoTime(); System.out.println(name + "\t" + (end - start) / 100_0000f + " ms"); } }
Benchmark { public void doSomething(String name, BenchmarkCallback callback) throws Exception { for (int i = 0; i < PREHEATING_TIMES; i++) { callback.doSomething(); } long start = System.nanoTime(); for (int i = 0; i < times; i++) { callback.doSomething(); } long end = System.nanoTime(); System.out.println(name + "\t" + (end - start) / 100_0000f + " ms"); } Benchmark();  Benchmark(int times); }
Benchmark { public void doSomething(String name, BenchmarkCallback callback) throws Exception { for (int i = 0; i < PREHEATING_TIMES; i++) { callback.doSomething(); } long start = System.nanoTime(); for (int i = 0; i < times; i++) { callback.doSomething(); } long end = System.nanoTime(); System.out.println(name + "\t" + (end - start) / 100_0000f + " ms"); } Benchmark();  Benchmark(int times); void doSomething(String name, BenchmarkCallback callback); }
Benchmark { public void doSomething(String name, BenchmarkCallback callback) throws Exception { for (int i = 0; i < PREHEATING_TIMES; i++) { callback.doSomething(); } long start = System.nanoTime(); for (int i = 0; i < times; i++) { callback.doSomething(); } long end = System.nanoTime(); System.out.println(name + "\t" + (end - start) / 100_0000f + " ms"); } Benchmark();  Benchmark(int times); void doSomething(String name, BenchmarkCallback callback);  }