Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@buchgr
Created April 22, 2015 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buchgr/4458a8bdb51dd58c82b4 to your computer and use it in GitHub Desktop.
Save buchgr/4458a8bdb51dd58c82b4 to your computer and use it in GitHub Desktop.
package io.netty.microbench.headers;
import io.netty.handler.codec.http.DefaultHttpHeaders;
import io.netty.handler.codec.http2.DefaultHttp2Headers;
import io.netty.microbench.headers.ExampleHeaders.HeaderExample;
import io.netty.util.AsciiString;
import io.netty.util.ByteString;
import io.netty.util.CharsetUtil;
import org.openjdk.jol.info.GraphLayout;
import java.util.Map;
import java.util.Map.Entry;
public class MemoryUsage {
private static class LowerBound {
private ByteString[] keys;
private ByteString[] values;
private int idx;
public LowerBound(int size) {
keys = new ByteString[size];
values = new ByteString[size];
}
public void add(ByteString key, ByteString value) {
keys[idx] = key;
values[idx] = value;
idx++;
}
}
public static void main(String... args) {
for (Entry<HeaderExample, Map<String, String>> header : ExampleHeaders.EXAMPLES.entrySet()) {
DefaultHttpHeaders http = new DefaultHttpHeaders(false);
DefaultHttp2Headers http2 = new DefaultHttp2Headers();
LowerBound lower = new LowerBound(header.getValue().size());
for (Entry<String, String> entry : header.getValue().entrySet()) {
http.add(new AsciiString(entry.getKey()), new AsciiString(entry.getValue()));
http2.add(new ByteString(entry.getKey(), CharsetUtil.US_ASCII), new ByteString(entry.getValue(), CharsetUtil.US_ASCII));
lower.add(new ByteString(entry.getKey(), CharsetUtil.US_ASCII), new ByteString(entry.getValue(), CharsetUtil.US_ASCII));
}
System.out.println(header.getKey().toString());
System.out.println("HTTP: " + GraphLayout.parseInstance(http).totalSize());
System.out.println("HTTP2: " + GraphLayout.parseInstance(http2).totalSize());
System.out.println("LOWER: " + GraphLayout.parseInstance(lower).totalSize());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment