Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StringReader;

Expand Down Expand Up @@ -49,7 +48,7 @@ private static void bench(JAXBContext c) throws JAXBException, IOException {
}
if (!(o instanceof Complex))
throw new JAXBException(o.getClass().getName());
c.createMarshaller().marshal(o, DUMP);
c.createMarshaller().marshal(o, NullOutputStream.INSTANCE);
}

@Benchmark
Expand All @@ -66,18 +65,4 @@ public void reference() throws JAXBException, IOException {
public void moxy() throws JAXBException, IOException {
bench(MOXY);
}

private static final OutputStream DUMP = new OutputStream() {
@Override
public void write(int b) throws IOException { // OK
}

@Override
public void write(byte[] b) throws IOException { // OK
}

@Override
public void write(byte[] b, int off, int len) throws IOException { // OK
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ public String charset() {
d.decode(b, c, true);
return c.flip().toString();
}

@Benchmark
public String string() {
byte[] bytes = DATA.getBytes(StandardCharsets.UTF_8);
return new String(bytes, StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class Main {
public static void main(String[] args) throws Exception {
Options o = new OptionsBuilder().forks(1).measurementIterations(10).verbosity(VerboseMode.NORMAL).warmupIterations(5).build();
Options o = new OptionsBuilder().forks(1).measurementIterations(10).verbosity(VerboseMode.SILENT).warmupIterations(5).build();

try (PrintStream w = args.length > 0 ? new PrintStream(Files.newOutputStream(Paths.get(args[0])), false, StandardCharsets.UTF_8) : System.out) {
for (Class<?> c : Arrays.asList(EncoderDecoder.class, BenchJaxb.class, BenchDocument.class, BenchProtostuff.class)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package unknow.server.bench;

import java.io.IOException;
import java.io.OutputStream;

public class NullOutputStream extends OutputStream {
public static final NullOutputStream INSTANCE = new NullOutputStream();

private NullOutputStream() {
}

@Override
public void write(int b) throws IOException { // OK
}

@Override
public void write(byte[] b) throws IOException { // OK
}

@Override
public void write(byte[] b, int off, int len) throws IOException { // OK
}

}
16 changes: 16 additions & 0 deletions unknow-server-bench/src/main/java/unknow/server/bench/Time.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package unknow.server.bench;

import org.openjdk.jmh.annotations.Benchmark;

public class Time {

@Benchmark
public long nanoTime() {
return System.nanoTime();
}

@Benchmark
public long currentMillies() {
return System.currentTimeMillis();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,12 @@ public static final Map<String, String> buildNsMapping(Map<String, Integer> ns)
if (map.isEmpty())
map.put(it.next(), "");
int i = 0;
while (it.hasNext())
map.put(it.next(), prefix(i++));
while (it.hasNext()) {
String p = prefix(i++);
if (p.equals("xml") || p.equals("xmlns"))
p = prefix(i++);
map.put(it.next(), p);
}
return map;
}

Expand All @@ -196,7 +200,7 @@ public static final String prefix(int t) {
int i = t % PREFIX_FIRST.length;
sb.append(PREFIX_FIRST[i]);
t -= i;
while (t > PREFIX_OTHER.length) {
while (t >= PREFIX_OTHER.length) {
i = t % PREFIX_OTHER.length;
sb.append(PREFIX_OTHER[i]);
t -= i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private FilterChain tryFind(ServletRequestImpl req, PartNode last, String path,
if (n == null)
break;
if (l < 0) {
req.setPathInfo(i - 1);
req.setPathInfo(path.length());
return n.exact;
}
last = n;
Expand Down