1 module dcrypt.benchmark.Benchmark; 2 3 public import std.datetime: StopWatch; 4 import std.conv; 5 import dcrypt.benchmark.BlockCipherBenchmark; 6 import dcrypt.benchmark.AEADCipherBenchmark; 7 import dcrypt.benchmark.DigestBenchmark; 8 //import dcrypt.benchmark.PKSS52ParameterGeneratorBenchmark; 9 import dcrypt.crypto.blockcipher; 10 import dcrypt.crypto.digest; 11 import dcrypt.crypto.modes.aead; 12 13 import std.stdio; 14 15 public class Benchmark { 16 17 18 /// Params: 19 /// length = the length of benchmark in bytes 20 /// ciphers = BlockCiphers to test 21 public static void doBenchmark(ulong length, BlockCipher[] ciphers...) { 22 writeln(); 23 24 printTabbed(BlockCipherBenchmark.header); 25 writeln(); 26 foreach(c; ciphers) { 27 auto bench = new BlockCipherBenchmark(c); 28 printTabbed(bench.benchmark(length)); 29 stdout.flush(); 30 } 31 } 32 33 public static void doBenchmark(ulong length, AEADCipher[] ciphers...) { 34 writeln(); 35 printTabbed(AEADCipherBenchmark.header); 36 writeln(); 37 foreach(c; ciphers) { 38 auto bench = new AEADCipherBenchmark(c); 39 printTabbed(bench.benchmark(length)); 40 stdout.flush(); 41 } 42 } 43 44 public static void doBenchmark(ulong length, Digest[] digests...) { 45 writeln(); 46 printTabbed(DigestBenchmark.header); 47 writeln(); 48 foreach(d; digests) { 49 auto bench = new DigestBenchmark(d); 50 printTabbed(bench.benchmark(length)); 51 stdout.flush(); 52 } 53 } 54 55 public static void doCurve25519Benchmark(ulong length) { 56 import dcrypt.benchmark.curve25519; 57 58 writeln(); 59 printTabbed(Curve25519Benchmark.header); 60 writeln(); 61 auto bench = new Curve25519Benchmark; 62 printTabbed(bench.benchmark(length)); 63 stdout.flush(); 64 65 } 66 67 // public static void doBenchmark(T)(PKCS5S2ParametersGenerator!T[] gen...) { 68 // writeln(); 69 // writeln(tabbed(padding, "algorithm", "iterations/s")); 70 // writeln(); 71 // foreach(g; gen) { 72 // auto bench = new PKSS52ParameterGeneratorBenchmark(g); 73 // writeln(bench.benchmark(0)); 74 // stdout.flush(); 75 // } 76 // } 77 78 /// do the calculations, (compute hashes, encrypt data, ...) 79 /// Params: length = length of benchmark (numbers of bytes to process) 80 /// Returns: a string containing the benchmark results 81 public abstract string[] benchmark(ulong length); 82 83 @trusted 84 static void printTabbed(string[] strs...) { 85 writefln("%-(%-20s%)", strs); 86 } 87 }