1. Micha Kops
  2. junit-benchmarking-tutorial

Commits

Micha Kops  committed 28ee514

Benchmarks restructured.

  • Participants
  • Parent commits 5382d43
  • Branches master

Comments (0)

Files changed (5)

File .gitignore

View file
  • Ignore whitespace
 .classpath
 .settings
 target
-infinitest.filters
+infinitest.filters
+.benchmarks.h2.db

File src/test/java/com/hascode/tutorial/BenchmarkOptionsExample.java

View file
  • Ignore whitespace
+package com.hascode.tutorial;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
+import com.carrotsearch.junitbenchmarks.BenchmarkRule;
+import com.carrotsearch.junitbenchmarks.Clock;
+
+@BenchmarkOptions(benchmarkRounds = 10, warmupRounds = 5, callgc = false, clock = Clock.REAL_TIME, concurrency = 4)
+public class BenchmarkOptionsExample {
+	ClassUnderTest classUnderTest = new ClassUnderTest();
+
+	@Rule
+	public BenchmarkRule benchmarkRun = new BenchmarkRule();
+
+	@Test
+	public void testSomething() throws Exception {
+		assertTrue(classUnderTest.doTest());
+	}
+
+	@BenchmarkOptions(benchmarkRounds = 20, warmupRounds = 4)
+	@Test
+	public void testSomethingWithAnotherSetup() throws Exception {
+		assertTrue(classUnderTest.doTest());
+	}
+}

File src/test/java/com/hascode/tutorial/GlobalBenchmarkOptionsExample.java

  • Ignore whitespace
-package com.hascode.tutorial;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Rule;
-import org.junit.Test;
-
-import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
-import com.carrotsearch.junitbenchmarks.BenchmarkRule;
-import com.carrotsearch.junitbenchmarks.Clock;
-
-@BenchmarkOptions(benchmarkRounds = 10, warmupRounds = 5, callgc = false, clock = Clock.REAL_TIME, concurrency = 4)
-public class GlobalBenchmarkOptionsExample {
-	ClassUnderTest classUnderTest = new ClassUnderTest();
-
-	@Rule
-	public BenchmarkRule benchmarkRun = new BenchmarkRule();
-
-	@Test
-	public void testSomething() throws Exception {
-		assertTrue(classUnderTest.doTest());
-	}
-}

File src/test/java/com/hascode/tutorial/SimpleTestBenchmark.java

View file
  • Ignore whitespace
+package com.hascode.tutorial;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.carrotsearch.junitbenchmarks.BenchmarkRule;
+
+public class SimpleTestBenchmark {
+	ClassUnderTest classUnderTest = new ClassUnderTest();
+
+	@Rule
+	public BenchmarkRule benchmarkRun = new BenchmarkRule();
+
+	@Test
+	public void testSomething() throws Exception {
+		assertTrue(classUnderTest.doTest());
+	}
+}

File src/test/java/com/hascode/tutorial/SomeTest.java

  • Ignore whitespace
-package com.hascode.tutorial;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Rule;
-import org.junit.Test;
-
-import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
-import com.carrotsearch.junitbenchmarks.BenchmarkRule;
-
-public class SomeTest {
-	ClassUnderTest classUnderTest = new ClassUnderTest();
-
-	@Rule
-	public BenchmarkRule benchmarkRun = new BenchmarkRule();
-
-	@Test
-	public void testSomething() throws Exception {
-		assertTrue(classUnderTest.doTest());
-	}
-
-	@BenchmarkOptions(benchmarkRounds = 20, warmupRounds = 4)
-	@Test
-	public void testSomethingWithWarmups() throws Exception {
-		assertTrue(classUnderTest.doTest());
-	}
-
-	class ClassUnderTest {
-		public boolean doTest() throws InterruptedException {
-			for (int i = 0; i < 3000000; i++)
-				new String("foo_" + i);
-
-			Thread.sleep(500);
-			return true;
-		}
-	}
-
-}