-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbenchmark.php
More file actions
34 lines (27 loc) · 964 Bytes
/
benchmark.php
File metadata and controls
34 lines (27 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
require_once(__DIR__."/vendor/autoload.php");
$ROUNDS = 100;
$privateKey = new EllipticCurve\PrivateKey();
$publicKey = $privateKey->publicKey();
$message = "This is a benchmark test message";
// Warmup
$sig = EllipticCurve\Ecdsa::sign($message, $privateKey);
EllipticCurve\Ecdsa::verify($message, $sig, $publicKey);
// Benchmark sign
$start = microtime(true);
for ($i = 0; $i < $ROUNDS; $i++) {
$sig = EllipticCurve\Ecdsa::sign($message, $privateKey);
}
$signTime = (microtime(true) - $start) / $ROUNDS * 1000;
// Benchmark verify
$start = microtime(true);
for ($i = 0; $i < $ROUNDS; $i++) {
EllipticCurve\Ecdsa::verify($message, $sig, $publicKey);
}
$verifyTime = (microtime(true) - $start) / $ROUNDS * 1000;
echo "\n";
echo sprintf("starkbank-ecdsa benchmark (%d rounds)\n", $ROUNDS);
echo "---------------------------------------\n";
echo sprintf("sign: %.1fms\n", $signTime);
echo sprintf("verify: %.1fms\n", $verifyTime);
echo "\n";