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:
@@ -26,9 +26,13 @@ public class CsvToEntryTransformer implements LineToEntryTransformer {
|
|||||||
public Optional<Entry> toEntry(final String line) throws IOException {
|
public Optional<Entry> toEntry(final String line) throws IOException {
|
||||||
Optional<Entry> result;
|
Optional<Entry> result;
|
||||||
try {
|
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);
|
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);
|
result = createEntry(columns);
|
||||||
|
|
||||||
@@ -52,7 +56,6 @@ public class CsvToEntryTransformer implements LineToEntryTransformer {
|
|||||||
switch (headers[i]) {
|
switch (headers[i]) {
|
||||||
case "@timestamp":
|
case "@timestamp":
|
||||||
epochMilli = fastISODateParser.parseAsEpochMilli(columns[i]);
|
epochMilli = fastISODateParser.parseAsEpochMilli(columns[i]);
|
||||||
;
|
|
||||||
break;
|
break;
|
||||||
case "duration":
|
case "duration":
|
||||||
duration = Long.parseLong(columns[i]);
|
duration = Long.parseLong(columns[i]);
|
||||||
|
|||||||
Reference in New Issue
Block a user