convex.benchmarks.SignatureBenchmark Maven / Gradle / Ivy
package convex.benchmarks;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import convex.core.crypto.AKeyPair;
import convex.core.crypto.AProvider;
import convex.core.crypto.ASignature;
import convex.core.crypto.bc.BCProvider;
import convex.core.crypto.sodium.SodiumProvider;
import convex.core.data.ABlob;
import convex.core.data.ACell;
import convex.core.data.Blobs;
import convex.core.data.Ref;
import convex.core.data.SignedData;
public class SignatureBenchmark {
protected static final AProvider SDPROVIDER=new SodiumProvider();
protected static final AProvider BCPROVIDER=new BCProvider();
protected static final AProvider PROVIDER=SDPROVIDER;
private static final AKeyPair KEYPAIR=PROVIDER.generate();
private static final SignedData SIGNED=makeSigned();
private static SignedData makeSigned() {
SignedData signed= KEYPAIR.signData(Blobs.fromHex("cafebabe"));
ACell.createPersisted(signed);
return signed;
}
private static final ASignature SIGNATURE=SIGNED.getSignature();
@Benchmark
public void signData() {
ABlob b=Blobs.createRandom(16);
KEYPAIR.signData(b);
}
@Benchmark
public void signVerify() {
ABlob b=Blobs.createRandom(16);
SignedData sd=KEYPAIR.signData(b);
ASignature sig=sd.getSignature();
sig.verify(b.getHash(), KEYPAIR.getAccountKey());
}
@Benchmark
public void verify() {
ASignature sig=SIGNATURE;
PROVIDER.verify(sig,SIGNED.getValue().getHash(), KEYPAIR.getAccountKey());
}
@SuppressWarnings("unchecked")
@Benchmark
public void verifyFromStore() {
SignedData signed=(SignedData) Ref.forHash(SIGNED.getHash()).getValue();
signed.checkSignature();
}
public static void main(String[] args) throws Exception {
Options opt = Benchmarks.createOptions(SignatureBenchmark.class);
new Runner(opt).run();
}
}