Pattern.split is faster than StringUtils.splitPreserveAll

Document the fact, so that I do not have to repeat the same
test a third time.
This commit is contained in:
2018-12-17 19:05:34 +01:00
parent 40f4506e13
commit d37508b7a1

View File

@@ -26,9 +26,13 @@ public class CsvToEntryTransformer implements LineToEntryTransformer {
public Optional<Entry> toEntry(final String line) throws IOException {
Optional<Entry> result;
try {
// For future reference:
// Pattern.split is actually faster than StringUtils.splitPreserveAll when the
// test runs longer.
// It seems that the JIT is compiling StringUtils.splitPreserveAll earlier, but
// Pattern.split is ending up getting the faster code in the long run.
final String[] columns = splitPattern.split(line);
if (columns.length == headers.length && !columns[0].startsWith("@")) {
if (columns.length == headers.length && columns[0].length() > 0 && columns[0].charAt(0) != '@') {
result = createEntry(columns);
@@ -52,7 +56,6 @@ public class CsvToEntryTransformer implements LineToEntryTransformer {
switch (headers[i]) {
case "@timestamp":
epochMilli = fastISODateParser.parseAsEpochMilli(columns[i]);
;
break;
case "duration":
duration = Long.parseLong(columns[i]);