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 24, 2023
1 parent 0b1f9ef commit d1d79d8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 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,58 @@

package org.opensearch.benchmark.index;

import com.fasterxml.jackson.core.io.doubleparser.FastDoubleParser;
import org.openjdk.jmh.annotations.*;
import org.opensearch.common.time.DateFormatter;
import com.ethlo.time.ITU;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.opensearch.common.logging.LogConfigurator;
import org.opensearch.common.time.DateFormatters;

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);
}
}

0 comments on commit d1d79d8

Please sign in to comment.