Skip to content

Commit

Permalink
Re-work test to use a warm-up followed by a "best of 5" approach to t…
Browse files Browse the repository at this point in the history
…ry and avoid false failures with the CI system. (Running on my laptop, homebrew is ~2x as fast).

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1657492 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Feb 5, 2015
1 parent d7491c5 commit 8459c95
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions test/org/apache/catalina/connector/TestResponsePerformance.java
Expand Up @@ -22,28 +22,53 @@
import org.junit.Test;

public class TestResponsePerformance {

private final int ITERATIONS = 100000;

@Test
public void testToAbsolutePerformance() throws Exception {
Request req = new TesterRequest();
Response resp = new Response();
resp.setRequest(req);

// Warm up
doHomebrew(resp);
doUri();

final int bestOf = 5;
final int winTarget = (bestOf + 1) / 2;
int homebrewWin = 0;
int count = 0;

while (count < bestOf && homebrewWin < winTarget) {
long homebrew = doHomebrew(resp);
long uri = doUri();
System.out.println("Current 'home-brew': " + homebrew + "ms, Using URI: " + uri + "ms");
if (homebrew < uri) {
homebrewWin++;
}
count++;
}
assertTrue(homebrewWin == winTarget);
}


private long doHomebrew(Response resp) {
long start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
for (int i = 0; i < ITERATIONS; i++) {
resp.toAbsolute("bar.html");
}
long homebrew = System.currentTimeMillis() - start;
return System.currentTimeMillis() - start;
}

start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {

private long doUri() {
long start = System.currentTimeMillis();
for (int i = 0; i < ITERATIONS; i++) {
URI base = URI.create(
"http://localhost:8080/level1/level2/foo.html");
base.resolve(URI.create("bar.html")).toASCIIString();
}
long uri = System.currentTimeMillis() - start;

System.out.println("Current 'home-brew': " + homebrew +
"ms, Using URI: " + uri + "ms");
assertTrue(homebrew < uri);
return System.currentTimeMillis() - start;
}
}

0 comments on commit 8459c95

Please sign in to comment.