Commits

Micha Kops committed ee3d048

Benchmarks with graphical output added.

  • Participants
  • Parent commits 8b6f1c7

Comments (0)

Files changed (4)

 .project
 .classpath
 .settings
-target
+target
+infinitest.filters
 			<version>0.5.0</version>
 			<scope>test</scope>
 		</dependency>
+		<dependency>
+			<groupId>com.h2database</groupId>
+			<artifactId>h2</artifactId>
+			<version>1.3.160</version>
+			<scope>test</scope>
+		</dependency>
 	</dependencies>
 
 	<build>

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

+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.annotation.AxisRange;
+import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart;
+
+@AxisRange(min = 0, max = 1)
+@BenchmarkMethodChart(filePrefix = "benchmark-lists")
+public class GraphicOutputTests {
+	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;
+		}
+	}
+
+}

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

 import com.carrotsearch.junitbenchmarks.BenchmarkRule;
 
 public class SomeTest {
+	ClassUnderTest classUnderTest = new ClassUnderTest();
+
 	@Rule
 	public BenchmarkRule benchmarkRun = new BenchmarkRule();
 
 	@Test
 	public void testSomething() throws Exception {
-		Thread.sleep(200);
-		assertTrue(!false);
+		assertTrue(classUnderTest.doTest());
 	}
 
-	@BenchmarkOptions(benchmarkRounds = 20, warmupRounds = 10)
+	@BenchmarkOptions(benchmarkRounds = 20, warmupRounds = 4)
 	@Test
-	public void testSomethingOther() throws Exception {
-		Thread.sleep(20);
-		assertTrue(!false);
+	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;
+		}
 	}
 
 }