diff options
-rw-r--r-- | src/cli/speed.cpp | 35 | ||||
-rwxr-xr-x | src/scripts/test_cli.py | 86 |
2 files changed, 72 insertions, 49 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp index cf35826e5..657cdd49b 100644 --- a/src/cli/speed.cpp +++ b/src/cli/speed.cpp @@ -1522,7 +1522,7 @@ class Speed final : public Command void bench_mp_mul(const std::chrono::milliseconds runtime) { - std::chrono::milliseconds runtime_per_size = runtime / 9; + std::chrono::milliseconds runtime_per_size = runtime; for(size_t bits : { 256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096 }) { std::unique_ptr<Timer> mul_timer = make_timer("BigInt mul " + std::to_string(bits)); @@ -1585,49 +1585,57 @@ class Speed final : public Command #endif #if defined(BOTAN_HAS_NUMBERTHEORY) - void bench_nistp_redc(const std::chrono::milliseconds total_runtime) + void bench_nistp_redc(const std::chrono::milliseconds runtime) { Botan::secure_vector<Botan::word> ws; - auto runtime = total_runtime / 5; - std::unique_ptr<Timer> p192_timer = make_timer("P-192 redc"); + Botan::BigInt r192(rng(), 192*2 - 1); while(p192_timer->under(runtime)) { - Botan::BigInt r192(rng(), 192*2 - 1); - p192_timer->run([&]() { Botan::redc_p192(r192, ws); }); + Botan::BigInt r = r192; + p192_timer->run([&]() { Botan::redc_p192(r, ws); }); + r192 += 1; } record_result(p192_timer); std::unique_ptr<Timer> p224_timer = make_timer("P-224 redc"); + Botan::BigInt r224(rng(), 224*2 - 1); while(p224_timer->under(runtime)) { - Botan::BigInt r224(rng(), 224*2 - 1); - p224_timer->run([&]() { Botan::redc_p224(r224, ws); }); + Botan::BigInt r = r224; + p224_timer->run([&]() { Botan::redc_p224(r, ws); }); + r224 += 1; } record_result(p224_timer); std::unique_ptr<Timer> p256_timer = make_timer("P-256 redc"); + Botan::BigInt r256(rng(), 256*2 - 1); while(p256_timer->under(runtime)) { - Botan::BigInt r256(rng(), 256*2 - 1); - p256_timer->run([&]() { Botan::redc_p256(r256, ws); }); + Botan::BigInt r = r256; + p256_timer->run([&]() { Botan::redc_p256(r, ws); }); + r256 += 1; } record_result(p256_timer); std::unique_ptr<Timer> p384_timer = make_timer("P-384 redc"); + Botan::BigInt r384(rng(), 384*2 - 1); while(p384_timer->under(runtime)) { - Botan::BigInt r384(rng(), 384*2 - 1); + Botan::BigInt r = r384; p384_timer->run([&]() { Botan::redc_p384(r384, ws); }); + r384 += 1; } record_result(p384_timer); std::unique_ptr<Timer> p521_timer = make_timer("P-521 redc"); + Botan::BigInt r521(rng(), 521*2 - 1); while(p521_timer->under(runtime)) { - Botan::BigInt r521(rng(), 521*2 - 1); + Botan::BigInt r = r521; p521_timer->run([&]() { Botan::redc_p521(r521, ws); }); + r521 += 1; } record_result(p521_timer); } @@ -2288,6 +2296,9 @@ class Speed final : public Command } record_result(scrypt_timer); + + if(scrypt_timer->events() == 1) + break; } } } diff --git a/src/scripts/test_cli.py b/src/scripts/test_cli.py index 1753592cc..353b9ed68 100755 --- a/src/scripts/test_cli.py +++ b/src/scripts/test_cli.py @@ -547,7 +547,9 @@ def cli_tls_client_hello_tests(): def cli_speed_tests(): # pylint: disable=too-many-branches - output = test_cli("speed", ["--msec=1", "--buf-size=64,512", "AES-128"], None).split('\n') + msec = 1 + + output = test_cli("speed", ["--msec=%d" % (msec), "--buf-size=64,512", "AES-128"], None).split('\n') if len(output) % 4 != 0: logging.error("Unexpected number of lines for AES-128 speed test") @@ -558,7 +560,7 @@ def cli_speed_tests(): if format_re.match(line) is None: logging.error("Unexpected line %s", line) - output = test_cli("speed", ["--msec=1", "ChaCha20", "SHA-256", "HMAC(SHA-256)"], None).split('\n') + output = test_cli("speed", ["--msec=%d" % (msec), "ChaCha20", "SHA-256", "HMAC(SHA-256)"], None).split('\n') # pylint: disable=line-too-long format_re = re.compile(r'^.* buffer size [0-9]+ bytes: [0-9]+\.[0-9]+ MiB\/sec .*\([0-9]+\.[0-9]+ MiB in [0-9]+\.[0-9]+ ms\)') @@ -566,7 +568,7 @@ def cli_speed_tests(): if format_re.match(line) is None: logging.error("Unexpected line %s", line) - output = test_cli("speed", ["--msec=1", "AES-128/GCM"], None).split('\n') + output = test_cli("speed", ["--msec=%d" % (msec), "AES-128/GCM"], None).split('\n') format_re_ks = re.compile(r'^AES-128/GCM\(16\) .* [0-9]+ key schedule/sec; [0-9]+\.[0-9]+ ms/op .*\([0-9]+ (op|ops) in [0-9]+ ms\)') format_re_cipher = re.compile(r'^AES-128/GCM\(16\) .* buffer size [0-9]+ bytes: [0-9]+\.[0-9]+ MiB\/sec .*\([0-9]+\.[0-9]+ MiB in [0-9]+\.[0-9]+ ms\)') for line in output: @@ -578,7 +580,7 @@ def cli_speed_tests(): "DH", "DSA", "ElGamal", "Ed25519", "Curve25519", "NEWHOPE", "McEliece", "RSA", "XMSS"] - output = test_cli("speed", ["--msec=5"] + pk_algos, None).split('\n') + output = test_cli("speed", ["--msec=%d" % (msec)] + pk_algos, None).split('\n') # ECDSA-secp256r1 106 keygen/sec; 9.35 ms/op 37489733 cycles/op (1 op in 9 ms) format_re = re.compile(r'^.* [0-9]+ ([A-Za-z ]+)/sec; [0-9]+\.[0-9]+ ms/op .*\([0-9]+ (op|ops) in [0-9]+ ms\)') @@ -592,12 +594,12 @@ def cli_speed_tests(): format_re = re.compile(r'^.* [0-9]+ /sec; [0-9]+\.[0-9]+ ms/op .*\([0-9]+ (op|ops) in [0-9]+(\.[0-9]+)? ms\)') for op in math_ops: - output = test_cli("speed", ["--msec=15", op], None).split('\n') + output = test_cli("speed", ["--msec=%d" % (msec), op], None).split('\n') for line in output: if format_re.match(line) is None: logging.error("Unexpected line %s", line) - output = test_cli("speed", ["--msec=5", "scrypt"], None).split('\n') + output = test_cli("speed", ["--msec=%d" % (msec), "scrypt"], None).split('\n') format_re = re.compile(r'^scrypt-[0-9]+-[0-9]+-[0-9]+ [0-9]+ /sec; [0-9]+\.[0-9]+ ms/op .*\([0-9]+ (op|ops) in [0-9]+ ms\)') @@ -605,7 +607,7 @@ def cli_speed_tests(): if format_re.match(line) is None: logging.error("Unexpected line %s", line) - output = test_cli("speed", ["--msec=5", "RNG"], None).split('\n') + output = test_cli("speed", ["--msec=%d" % (msec), "RNG"], None).split('\n') # ChaCha_RNG generate buffer size 1024 bytes: 954.431 MiB/sec 4.01 cycles/byte (477.22 MiB in 500.00 ms) format_re = re.compile(r'^.* generate buffer size [0-9]+ bytes: [0-9]+\.[0-9]+ MiB/sec .*\([0-9]+\.[0-9]+ MiB in [0-9]+\.[0-9]+ ms') @@ -614,13 +616,13 @@ def cli_speed_tests(): logging.error("Unexpected line %s", line) # Entropy source rdseed output 128 bytes estimated entropy 0 in 0.02168 ms total samples 32 - output = test_cli("speed", ["--msec=5", "entropy"], None).split('\n') + output = test_cli("speed", ["--msec=%d" % (msec), "entropy"], None).split('\n') format_re = re.compile(r'^Entropy source [_a-z]+ output [0-9]+ bytes estimated entropy [0-9]+ in [0-9]+\.[0-9]+ ms .*total samples [0-9]+') for line in output: if format_re.match(line) is None: logging.error("Unexpected line %s", line) - output = test_cli("speed", ["--msec=5", "--format=json", "AES-128"], None) + output = test_cli("speed", ["--msec=%d" % (msec), "--format=json", "AES-128"], None) json_blob = json.loads(output) if len(json_blob) < 2: @@ -659,34 +661,44 @@ def main(args=None): start_time = time.time() - cli_asn1_tests() - cli_base64_tests() - cli_bcrypt_tests() - cli_cc_enc_tests() - cli_compress_tests() - cli_config_tests() - cli_dl_group_info_tests() - cli_ec_group_info_tests() - cli_factor_tests() - cli_gen_dl_group_tests() - cli_gen_prime_tests() - cli_hash_tests() - cli_help_tests() - cli_hex_tests() - cli_hmac_tests() - cli_is_prime_tests() - cli_key_tests() - cli_mod_inverse_tests() - cli_pk_encrypt_tests() - cli_pk_workfactor_tests() - cli_psk_db_tests() - cli_rng_tests() - cli_speed_tests() - cli_timing_test_tests() - cli_tls_ciphersuite_tests() - cli_tls_client_hello_tests() - cli_tls_socket_tests() - cli_version_tests() + test_fns = [ + cli_asn1_tests, + cli_asn1_tests, + cli_base64_tests, + cli_bcrypt_tests, + cli_cc_enc_tests, + cli_compress_tests, + cli_config_tests, + cli_dl_group_info_tests, + cli_ec_group_info_tests, + cli_factor_tests, + cli_gen_dl_group_tests, + cli_gen_prime_tests, + cli_hash_tests, + cli_help_tests, + cli_hex_tests, + cli_hmac_tests, + cli_is_prime_tests, + cli_key_tests, + cli_mod_inverse_tests, + cli_pk_encrypt_tests, + cli_pk_workfactor_tests, + cli_psk_db_tests, + cli_rng_tests, + cli_speed_tests, + cli_timing_test_tests, + cli_tls_ciphersuite_tests, + cli_tls_client_hello_tests, + cli_tls_socket_tests, + cli_version_tests, + ] + + for fn in test_fns: + start = time.time() + fn() + end = time.time() + #print("Ran %s in %.02f" % (fn.__name__, end-start)) + end_time = time.time() |