You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by GitBox <gi...@apache.org> on 2018/12/14 15:14:47 UTC
[GitHub] amarkevich opened a new pull request #483: HttpHeaderHelper:
String.replace instead of Pattern.matcher().replaceAll
amarkevich opened a new pull request #483: HttpHeaderHelper: String.replace instead of Pattern.matcher().replaceAll
URL: https://github.com/apache/cxf/pull/483
benchmark [1] results:
- old: 40 MB 47 ms
- new: 9 MB 0 ms
1.
```
public class HttpHeaderHelperMapCharsetTest {
private static final int CNT = 131072;
static final String charset = java.nio.charset.StandardCharsets.UTF_8.name();
private static final String[] STR = new String[CNT];
static {
for (int i = 0; i < CNT; ++i) {
if (i % 3 == 0) {
STR[i] = "\"" + charset + "\"";
} else if (i % 3 == 1) {
STR[i] = "'" + charset + "'";
} else {
STR[i] = charset;
}
}
}
@org.junit.Test
public void mapCharset() {
metrics("HttpHeaderHelper::mapCharset", HttpHeaderHelper::mapCharset);
}
@org.junit.Test
public void mapCharset2() {
metrics("HttpHeaderHelper::mapCharset2", HttpHeaderHelper::mapCharset2);
}
private static void metrics(String label, java.util.function.Function<String, String> f) {
Runtime.getRuntime().gc();
long m = Runtime.getRuntime().freeMemory();
long t = System.currentTimeMillis();
for (int i = 0; i < CNT; ++i) {
org.junit.Assert.assertEquals(charset, f.apply(STR[i]));
}
System.out.println(label + ": " + ((m - Runtime.getRuntime().freeMemory()) / (1024 * 1024)) + " MB "
+ (System.currentTimeMillis() - t) + " ms");
}
public static void main(String[] args) {
final HttpHeaderHelperMapCharsetTest splitTest = new HttpHeaderHelperMapCharsetTest();
for (int i = 0; i < 10; ++i) {
System.out.println("Round #" + i);
splitTest.mapCharset();
splitTest.mapCharset2();
}
}
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services