|
| 1 | +package org.simdjson; |
| 2 | + |
| 3 | +import org.openjdk.jmh.annotations.Benchmark; |
| 4 | +import org.openjdk.jmh.annotations.BenchmarkMode; |
| 5 | +import org.openjdk.jmh.annotations.Level; |
| 6 | +import org.openjdk.jmh.annotations.Mode; |
| 7 | +import org.openjdk.jmh.annotations.OutputTimeUnit; |
| 8 | +import org.openjdk.jmh.annotations.Param; |
| 9 | +import org.openjdk.jmh.annotations.Scope; |
| 10 | +import org.openjdk.jmh.annotations.Setup; |
| 11 | +import org.openjdk.jmh.annotations.State; |
| 12 | + |
| 13 | +import java.io.IOException; |
| 14 | +import java.util.concurrent.TimeUnit; |
| 15 | + |
| 16 | +import static org.simdjson.SimdJsonPaddingUtil.padWithSpaces; |
| 17 | + |
| 18 | +@State(Scope.Benchmark) |
| 19 | +@BenchmarkMode(Mode.Throughput) |
| 20 | +@OutputTimeUnit(TimeUnit.SECONDS) |
| 21 | +public class NumberParserBenchmark { |
| 22 | + |
| 23 | + private final Tape tape = new Tape(100); |
| 24 | + private final NumberParser numberParser = new NumberParser(tape); |
| 25 | + |
| 26 | + @Param({ |
| 27 | + "2.2250738585072013e-308", // fast path |
| 28 | + "1.00000000000000188558920870223463870174566020691753515394643550663070558368373221972569761144603605635692374830246134201063722058e-309" // slow path |
| 29 | + }) |
| 30 | + String number; |
| 31 | + byte[] numberUtf8Bytes; |
| 32 | + |
| 33 | + @Setup(Level.Trial) |
| 34 | + public void setup() throws IOException { |
| 35 | + numberUtf8Bytes = padWithSpaces(number); |
| 36 | + } |
| 37 | + |
| 38 | + @Benchmark |
| 39 | + public double baseline() { |
| 40 | + return Double.parseDouble(number); |
| 41 | + } |
| 42 | + |
| 43 | + @Benchmark |
| 44 | + public double simdjson() { |
| 45 | + tape.reset(); |
| 46 | + numberParser.parseNumber(numberUtf8Bytes, 0); |
| 47 | + return tape.getDouble(0); |
| 48 | + } |
| 49 | +} |
0 commit comments