|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +package org.elasticsearch.benchmark.compute.operator; |
| 11 | + |
| 12 | +import org.apache.lucene.document.InetAddressPoint; |
| 13 | +import org.apache.lucene.util.BytesRef; |
| 14 | +import org.elasticsearch.common.breaker.NoopCircuitBreaker; |
| 15 | +import org.elasticsearch.common.network.InetAddresses; |
| 16 | +import org.elasticsearch.compute.operator.BreakingBytesRefBuilder; |
| 17 | +import org.elasticsearch.xpack.esql.expression.function.scalar.convert.ParseIp; |
| 18 | +import org.openjdk.jmh.annotations.Benchmark; |
| 19 | +import org.openjdk.jmh.annotations.BenchmarkMode; |
| 20 | +import org.openjdk.jmh.annotations.Fork; |
| 21 | +import org.openjdk.jmh.annotations.Measurement; |
| 22 | +import org.openjdk.jmh.annotations.Mode; |
| 23 | +import org.openjdk.jmh.annotations.OutputTimeUnit; |
| 24 | +import org.openjdk.jmh.annotations.Scope; |
| 25 | +import org.openjdk.jmh.annotations.State; |
| 26 | +import org.openjdk.jmh.annotations.Warmup; |
| 27 | + |
| 28 | +import java.net.InetAddress; |
| 29 | +import java.util.concurrent.TimeUnit; |
| 30 | + |
| 31 | +@Warmup(iterations = 5) |
| 32 | +@Measurement(iterations = 7) |
| 33 | +@BenchmarkMode(Mode.AverageTime) |
| 34 | +@OutputTimeUnit(TimeUnit.NANOSECONDS) |
| 35 | +@State(Scope.Thread) |
| 36 | +@Fork(1) |
| 37 | +public class ParseIpBenchmark { |
| 38 | + private final BytesRef ip = new BytesRef("192.168.0.1"); |
| 39 | + private final BreakingBytesRefBuilder scratch = ParseIp.buildScratch(new NoopCircuitBreaker("request")); |
| 40 | + |
| 41 | + @Benchmark |
| 42 | + public BytesRef leadingZerosRejected() { |
| 43 | + return ParseIp.leadingZerosRejected(ip, scratch); |
| 44 | + } |
| 45 | + |
| 46 | + @Benchmark |
| 47 | + public BytesRef leadingZerosAreDecimal() { |
| 48 | + return ParseIp.leadingZerosAreDecimal(ip, scratch); |
| 49 | + } |
| 50 | + |
| 51 | + @Benchmark |
| 52 | + public BytesRef leadingZerosAreOctal() { |
| 53 | + return ParseIp.leadingZerosAreOctal(ip, scratch); |
| 54 | + } |
| 55 | + |
| 56 | + @Benchmark |
| 57 | + public BytesRef original() { |
| 58 | + InetAddress inetAddress = InetAddresses.forString(ip.utf8ToString()); |
| 59 | + return new BytesRef(InetAddressPoint.encode(inetAddress)); |
| 60 | + } |
| 61 | +} |
0 commit comments