AsciiStringBenchmark Class — netty Architecture
Architecture documentation for the AsciiStringBenchmark class in AsciiStringBenchmark.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD aff6af82_71b2_329f_41cf_d30a3ab60974["AsciiStringBenchmark"] 136c0858_2567_3f81_ff97_628ef3a615f4["AsciiStringBenchmark.java"] aff6af82_71b2_329f_41cf_d30a3ab60974 -->|defined in| 136c0858_2567_3f81_ff97_628ef3a615f4 ecd09171_6c98_b906_343c_1f47ef7eb317["setup()"] aff6af82_71b2_329f_41cf_d30a3ab60974 -->|method| ecd09171_6c98_b906_343c_1f47ef7eb317 54f38c0e_e554_be86_7ee6_6c67d071e662["equalsIgnoreCaseBench()"] aff6af82_71b2_329f_41cf_d30a3ab60974 -->|method| 54f38c0e_e554_be86_7ee6_6c67d071e662 238f98e6_2277_c432_c38b_659eb167b882["hashCodeBenchBytesOld()"] aff6af82_71b2_329f_41cf_d30a3ab60974 -->|method| 238f98e6_2277_c432_c38b_659eb167b882 a8984e07_0ae7_261a_3e8d_e178f0e9b7c0["hashCodeBenchBytesNew()"] aff6af82_71b2_329f_41cf_d30a3ab60974 -->|method| a8984e07_0ae7_261a_3e8d_e178f0e9b7c0 3abd1b73_d937_ec50_e392_aafe8d89a97f["hashCodeBenchCharSequenceOld()"] aff6af82_71b2_329f_41cf_d30a3ab60974 -->|method| 3abd1b73_d937_ec50_e392_aafe8d89a97f a2101e46_0e55_37c2_105d_4c377a02570d["hashCodeBenchCharSequenceNew()"] aff6af82_71b2_329f_41cf_d30a3ab60974 -->|method| a2101e46_0e55_37c2_105d_4c377a02570d
Relationship Graph
Source Code
microbench/src/main/java/io/netty/microbenchmark/common/AsciiStringBenchmark.java lines 34–96
@Threads(1)
@Measurement(iterations = 5, time = 200, timeUnit = MILLISECONDS)
@Warmup(iterations = 5, time = 200, timeUnit = MILLISECONDS)
public class AsciiStringBenchmark extends AbstractMicrobenchmark {
@Param({ "3", "5", "7", "8", "10", "20", "50", "100", "1000" })
public int size;
private AsciiString asciiString;
private String string;
private static final Random random = new Random();
private AsciiString connection;
private AsciiString Connection;
@Setup(Level.Trial)
public void setup() {
byte[] bytes = new byte[size];
random.nextBytes(bytes);
asciiString = new AsciiString(bytes, false);
string = new String(bytes, CharsetUtil.US_ASCII);
connection = AsciiString.cached("connection");
Connection = AsciiString.cached("Connection");
}
@Benchmark
public boolean equalsIgnoreCaseBench() {
return Connection.contentEqualsIgnoreCase(connection);
}
@Benchmark
public int hashCodeBenchBytesOld() {
int h = 0;
final int end = asciiString.arrayOffset() + asciiString.length();
for (int i = asciiString.arrayOffset(); i < end; ++i) {
// masking with 0x1F reduces the number of overall bits that impact the hash code but makes the hash
// code the same regardless of character case (upper case or lower case hash is the same).
h = h * 31 + (asciiString.array()[i] & 0x1F);
}
return h;
}
@Benchmark
public int hashCodeBenchBytesNew() {
return PlatformDependent.hashCodeAscii(asciiString.array(), asciiString.arrayOffset(), asciiString.length());
}
@Benchmark
public int hashCodeBenchCharSequenceOld() {
int h = 0;
for (int i = 0; i < string.length(); ++i) {
// masking with 0x1F reduces the number of overall bits that impact the hash code but makes the hash
// code the same regardless of character case (upper case or lower case hash is the same).
h = h * 31 + (string.charAt(i) & 0x1F);
}
return h;
}
@Benchmark
public int hashCodeBenchCharSequenceNew() {
return PlatformDependent.hashCodeAscii(string);
}
}
Source
Frequently Asked Questions
What is the AsciiStringBenchmark class?
AsciiStringBenchmark is a class in the netty codebase, defined in microbench/src/main/java/io/netty/microbenchmark/common/AsciiStringBenchmark.java.
Where is AsciiStringBenchmark defined?
AsciiStringBenchmark is defined in microbench/src/main/java/io/netty/microbenchmark/common/AsciiStringBenchmark.java at line 34.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free