forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Microbenchmarks for H3
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
benchmarks/src/main/java/org/elasticsearch/benchmark/h3/H3Benchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
package org.elasticsearch.benchmark.h3; | ||
|
||
import org.elasticsearch.h3.H3; | ||
import org.openjdk.jmh.Main; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 25, time = 1, timeUnit = TimeUnit.SECONDS) | ||
@Fork(1) | ||
public class H3Benchmark { | ||
|
||
@Benchmark | ||
public void pointToH3(H3State state, Blackhole bh) { | ||
for (int i = 0; i < state.points.length; i++) { | ||
for (int res = 0; res <= 15; res++) { | ||
bh.consume(H3.geoToH3(state.points[i][0], state.points[i][1], res)); | ||
} | ||
} | ||
} | ||
|
||
@Benchmark | ||
public void h3Boundary(H3State state, Blackhole bh) { | ||
for (int i = 0; i < state.h3.length; i++) { | ||
bh.consume(H3.h3ToGeoBoundary(state.h3[i])); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
Main.main(args); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
benchmarks/src/main/java/org/elasticsearch/benchmark/h3/H3State.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
package org.elasticsearch.benchmark.h3; | ||
|
||
import org.elasticsearch.h3.H3; | ||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
|
||
import java.io.IOException; | ||
import java.util.Random; | ||
|
||
@State(Scope.Benchmark) | ||
public class H3State { | ||
|
||
double[][] points = new double[1000][2]; | ||
long[] h3 = new long[1000]; | ||
|
||
@Setup(Level.Trial) | ||
public void setupTrial() throws IOException { | ||
Random random = new Random(1234); | ||
for (int i = 0; i < points.length; i++) { | ||
points[i][0] = random.nextDouble() * 180 - 90; // lat | ||
points[i][1] = random.nextDouble() * 360 - 180; // lon | ||
int res = random.nextInt(16); // resolution | ||
h3[i] = H3.geoToH3(points[i][0], points[i][1], res); | ||
} | ||
} | ||
} |