Benchmark tweaks

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@919418 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2010-03-05 14:00:58 +00:00
parent 1387923be8
commit bafc57ec16
2 changed files with 27 additions and 3 deletions

View File

@ -54,6 +54,11 @@
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>${pom.version}</version> <version>${pom.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.1-alpha2-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>commons-httpclient</groupId> <groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId> <artifactId>commons-httpclient</artifactId>
@ -105,6 +110,23 @@
<showDeprecations>${maven.compile.deprecation}</showDeprecations> <showDeprecations>${maven.compile.deprecation}</showDeprecations>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>test-run</id>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.apache.http.client.benchmark.Benchmark</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>

View File

@ -30,7 +30,6 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Writer; import java.io.Writer;
import java.net.URI; import java.net.URI;
import java.util.Random;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -76,8 +75,10 @@ public class Benchmark {
}; };
byte[] content = new byte[contentLen]; byte[] content = new byte[contentLen];
Random rnd = new Random(); int r = Math.abs(content.hashCode());
rnd.nextBytes(content); for (int i = 0; i < content.length; i++) {
content[i] = (byte) ((r + i) % 96 + 32);
}
URI target1 = new URI("http", null, "localhost", port, "/rnd", "c=" + contentLen, null); URI target1 = new URI("http", null, "localhost", port, "/rnd", "c=" + contentLen, null);
URI target2 = new URI("http", null, "localhost", port, "/echo", null, null); URI target2 = new URI("http", null, "localhost", port, "/echo", null, null);
@ -174,6 +175,7 @@ public class Benchmark {
InputStream instream = request.getInputStream(); InputStream instream = request.getInputStream();
if (instream != null) { if (instream != null) {
IO.copy(instream, buffer); IO.copy(instream, buffer);
buffer.flush();
} }
byte[] content = buffer.getBuf(); byte[] content = buffer.getBuf();