Permalink
Browse files

optimization

  • Loading branch information...
patriot1burke committed Jan 24, 2014
1 parent 0486357 commit 7e0537006841cb8df165158dcd66ac879f8685c3
@@ -0,0 +1,72 @@
+package org.jboss.resteasy.test.profiling;
+
+import org.jboss.resteasy.core.ResourceMethodRegistry;
+import org.jboss.resteasy.mock.MockHttpRequest;
+import org.jboss.resteasy.mock.MockHttpResponse;
+import org.jboss.resteasy.spi.Registry;
+import org.jboss.resteasy.spi.ResteasyDeployment;
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
+import org.junit.Test;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import java.io.ByteArrayInputStream;
+
+/**
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public class MockedProfilingTest
+{
+ @Path("/test")
+ public static class CleartextResource
+ {
+
+ @POST
+ @Produces("text/plain")
+ @Consumes("text/plain")
+ @Path("create")
+ public String create(String cust)
+ {
+ //System.out.println("cust: " + cust);
+ return cust;
+ }
+
+ }
+
+ @Test
+ public void testCleartext() throws Exception
+ {
+ final int WARMUP = 10;
+ final int INTERATIONS = 100;
+
+ ResteasyDeployment deployment = new ResteasyDeployment();
+ deployment.start();
+ Registry registry = deployment.getRegistry();
+ registry.addPerRequestResource(CleartextResource.class);
+
+ MockHttpResponse response = new MockHttpResponse();
+ MockHttpRequest request = MockHttpRequest.post("/test/create").accept(MediaType.TEXT_PLAIN).contentType(MediaType.TEXT_PLAIN);
+ ByteArrayInputStream stream = new ByteArrayInputStream("hello".getBytes());
+ request.setInputStream(stream);
+
+ for (int i = 0; i < WARMUP; i++)
+ {
+ deployment.getDispatcher().invoke(request, response);
+ stream.reset();
+ }
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < INTERATIONS; i++)
+ {
+ deployment.getDispatcher().invoke(request, response);
+ stream.reset();
+ }
+ long end = System.currentTimeMillis() - start;
+
+ System.out.println("Time took: " + end);
+
+ }
+}
@@ -13,6 +13,7 @@
import java.net.URI;
import java.net.URLDecoder;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
/**
@@ -40,7 +41,7 @@
private URI baseURI;
private List<String> matchedUris;
private List<String> encodedMatchedUris;
- private List<String> encodedMatchedPaths = new ArrayList<String>();
+ private List<String> encodedMatchedPaths = new LinkedList<String>();
private List<Object> ancestors;
@@ -312,12 +313,12 @@ protected void extractParameters(String queryString)
{
if (decode)
{
- if (matchedUris == null) matchedUris = new ArrayList<String>();
+ if (matchedUris == null) matchedUris = new LinkedList<String>();
return matchedUris;
}
else
{
- if (encodedMatchedUris == null) encodedMatchedUris = new ArrayList<String>();
+ if (encodedMatchedUris == null) encodedMatchedUris = new LinkedList<String>();
return encodedMatchedUris;
}
}
@@ -329,14 +330,14 @@ protected void extractParameters(String queryString)
public List<Object> getMatchedResources()
{
- if (ancestors == null) ancestors = new ArrayList<Object>();
+ if (ancestors == null) ancestors = new LinkedList<Object>();
return ancestors;
}
public void pushCurrentResource(Object resource)
{
- if (ancestors == null) ancestors = new ArrayList<Object>();
+ if (ancestors == null) ancestors = new LinkedList<Object>();
ancestors.add(0, resource);
}
@@ -362,10 +363,10 @@ public void pushMatchedURI(String encoded)
if (encoded.endsWith("/")) encoded = encoded.substring(0, encoded.length() - 1);
if (encoded.startsWith("/")) encoded = encoded.substring(1);
String decoded = Encode.decode(encoded);
- if (encodedMatchedUris == null) encodedMatchedUris = new ArrayList<String>();
+ if (encodedMatchedUris == null) encodedMatchedUris = new LinkedList<String>();
encodedMatchedUris.add(0, encoded);
- if (matchedUris == null) matchedUris = new ArrayList<String>();
+ if (matchedUris == null) matchedUris = new LinkedList<String>();
matchedUris.add(0, decoded);
}

0 comments on commit 7e05370

Please sign in to comment.