/* * Copyright 2019 ConsenSys AG. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ package tech.pegasys.teku.util.bench; import java.util.concurrent.TimeUnit; import org.apache.tuweni.bytes.Bytes; 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.Scope; import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.infra.Blackhole; import tech.pegasys.teku.util.hashToG2.HashToCurve; import tech.pegasys.teku.util.mikuli.G2Point; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MILLISECONDS) @State(Scope.Benchmark) @Fork(value = 1) @Warmup(iterations = 2, time = 10) @Measurement(iterations = 8, time = 10) public class BenchBLS { private Bytes message; private Bytes suite = Bytes.fromHexString("0x02"); @Setup public void setup() { message = Bytes.random(32); } @Benchmark public void hashToCurve(Blackhole blackhole) { G2Point result = new G2Point(HashToCurve.hashToG2(message, suite)); blackhole.consume(result); } }