summaryrefslogtreecommitdiff
path: root/test/BenchTest.mc
diff options
context:
space:
mode:
Diffstat (limited to 'test/BenchTest.mc')
-rw-r--r--test/BenchTest.mc43
1 files changed, 42 insertions, 1 deletions
diff --git a/test/BenchTest.mc b/test/BenchTest.mc
index 7e1f612..df12db1 100644
--- a/test/BenchTest.mc
+++ b/test/BenchTest.mc
@@ -1,5 +1,5 @@
// Author: cirakg & claude ai
-// Summary: Benchmarks of the crypto and OTP primitives; logs BENCH lines for docs/PERFORMANCE.md, never fails.
+// Summary: Benchmarks of the crypto, OTP and storage code; logs BENCH lines for docs/PERFORMANCE.md, never fails.
//
// Simulator timings run on the PC's CPU, so they only compare primitives with
// each other (for example how much SHA-512 costs against native SHA-1).
@@ -55,6 +55,38 @@ module Bench {
SelfTest.run();
}
}
+
+ // A vault with 20 OTP entries, for list and open timings.
+ class VaultCases {
+ var vault as Vault;
+ var ids as Array<String>;
+
+ function initialize() {
+ vault = new Vault(new MemoryBackend(), new FakeTime());
+ for (var i = 0; i < 20; i++) {
+ vault.add(StorageFixtures.totp("Entry " + i));
+ }
+ ids = vault.ids();
+ }
+
+ // What the list does on start-up: every header.
+ function readAllHeaders() as Void {
+ for (var i = 0; i < ids.size(); i++) {
+ vault.header(ids[i]);
+ }
+ }
+
+ // What showing one code does: decrypt one entry.
+ function openOne() as Void {
+ vault.open(ids[0]).wipeSecrets();
+ }
+
+ function addOne() as Void {
+ var e = StorageFixtures.totp("Bench");
+ vault.add(e);
+ vault.remove(e.id);
+ }
+ }
}
(:test)
@@ -68,3 +100,12 @@ function benchmarkPrimitives(logger as Test.Logger) as Boolean {
Bench.measure(logger, "self_test", 3, c.method(:selfTest));
return true;
}
+
+(:test)
+function benchmarkVault(logger as Test.Logger) as Boolean {
+ var v = new Bench.VaultCases();
+ Bench.measure(logger, "vault_20_headers", 5, v.method(:readAllHeaders));
+ Bench.measure(logger, "vault_open_entry", 20, v.method(:openOne));
+ Bench.measure(logger, "vault_add_remove", 10, v.method(:addOne));
+ return true;
+}