Skip to content

Commit

Permalink
Added benchmarking for different parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Prabhat Sharma committed Nov 23, 2023
1 parent 0b1f9ef commit b86916c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {
}
api "org.openjdk.jmh:jmh-core:$versions.jmh"
annotationProcessor "org.openjdk.jmh:jmh-generator-annprocess:$versions.jmh"
implementation 'com.ethlo.time:itu:1.7.0'
// Dependencies of JMH
runtimeOnly 'net.sf.jopt-simple:jopt-simple:5.0.4'
runtimeOnly 'org.apache.commons:commons-math3:3.6.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,53 @@

package org.opensearch.benchmark.index;

import com.fasterxml.jackson.core.io.doubleparser.FastDoubleParser;
import com.ethlo.time.ITU;
import org.openjdk.jmh.annotations.*;
import org.opensearch.common.logging.LogConfigurator;
import org.opensearch.common.time.DateFormatter;
import org.opensearch.common.time.DateFormatters;

import java.io.IOException;
import java.util.Locale;
import java.util.Random;
import java.util.concurrent.TimeUnit;

@Fork(3)
@Warmup(iterations = 1)
@Measurement(iterations = 3)
@Warmup(iterations = 5)
@Measurement(iterations = 10)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@SuppressWarnings("unused") // invoked by benchmarking framework
public class DocumentParsingBenchmark {

private String val = Double.toString(new Random().nextDouble());
@Setup
public void setup() {
LogConfigurator.setNodeName("test");
}

private static DateFormatter STRICT_FORMATTER = DateFormatter.forPattern("yyyy-MM-dd HH:mm:ss").withLocale(Locale.ROOT);
@Param({
"2023-01-01T23:38:34.000Z",
"1970-01-01T00:16:12.675Z",
"5050-01-01T12:02:01.123Z",
})
public String dateString;
//private static DateFormatter STRICT_FORMATTER = DateFormatter.forPattern("yyyy-MM-dd HH:mm:ss").withLocale(Locale.ROOT);
//private static DateFormatter FALLBACK_FORMATTER = DateFormatter.forPattern("strict_date_optional_time||epoch_millis");

@Benchmark
public void candidate() throws Exception {
public void isoOffsetDateFormatter() throws Exception {
//STRICT_FORMATTER.parse(nowEpoch);
DateFormatters.FAST_ISO_LOCAL_DATE_FORMATTER.parse("2022-04-05 22:00:12");
DateFormatters.ISO_OFFSET_DATE_FORMATTER.parse(dateString);
}

@Benchmark
public void charDateFormatter() throws Exception {
DateFormatters.CHAR_DATE_FORMATTER.parse(dateString);
}

@Benchmark
public void baseline() throws Exception {
STRICT_FORMATTER.parse("2022-04-05 22:00:12");
public void benchITUParser() {
ITU.parseDateTime(dateString);
}
}
2 changes: 1 addition & 1 deletion distribution/src/config/opensearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
# Use a descriptive name for the node:
#
#node.name: node-1
node.name: node-1
#
# Add custom attributes to the node:
#
Expand Down

0 comments on commit b86916c

Please sign in to comment.