Added bechmarks

This commit is contained in:
Thorsten Sommer 2020-01-06 20:54:09 +01:00
parent 6f6c9f0abe
commit 7822a60100

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
using System.Text;
@ -248,6 +249,66 @@ namespace Ed25519_Tests
Assert.That(signaturePrivateKeyEncrypted.ToArray(), Is.Not.EqualTo(signaturePrivateKeyDecrypted.ToArray()));
}
[Test]
public void TestPerformanceSigning()
{
var privateKey = Signer.GeneratePrivateKey();
var publicKey = privateKey.ExtractPublicKey();
var rng = new Random();
var payload = new byte[1_024];
var stopwatch = new Stopwatch();
var desiredRuntime = TimeSpan.FromSeconds(30);
var counter = 0;
while (true)
{
counter++;
rng.NextBytes(payload);
stopwatch.Start();
Signer.Sign(payload, privateKey, publicKey);
stopwatch.Stop();
if(stopwatch.Elapsed >= desiredRuntime)
break;
}
var result = counter / stopwatch.Elapsed.TotalSeconds;
TestContext.Write($"Benchmark for signing messages: {result:0.00} messages/second");
Assert.That(true);
}
[Test]
public void TestPerformanceValidation()
{
var privateKey = Signer.GeneratePrivateKey();
var publicKey = privateKey.ExtractPublicKey();
var rng = new Random();
var payload = new byte[1_024];
var stopwatch = new Stopwatch();
var desiredRuntime = TimeSpan.FromSeconds(30);
var counter = 0;
while (true)
{
counter++;
rng.NextBytes(payload);
var signature = Signer.Sign(payload, privateKey, publicKey);
stopwatch.Start();
Signer.Validate(signature, payload, publicKey);
stopwatch.Stop();
if (stopwatch.Elapsed >= desiredRuntime)
break;
}
var result = counter / stopwatch.Elapsed.TotalSeconds;
TestContext.Write($"Benchmark for validation of messages: {result:0.00} messages/second");
Assert.That(true);
}
// See https://tools.ietf.org/html/rfc8032#section-7.1
[Test]
public void TestRFC8032Test01EmptyMessage()