From 4cddb26908bde48047e4b6e383c4b061c289a5e5 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 10 Nov 2022 03:41:28 +0100 Subject: [PATCH] atbash.py: Tighten up the benchmarks (#7977) * atbash.py: Tighten up the benchmarks * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> --- DIRECTORY.md | 1 + ciphers/atbash.py | 21 ++++----------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 76c7f9dea..5f314c317 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -995,6 +995,7 @@ * [Sol1](project_euler/problem_686/sol1.py) ## Quantum + * [Bb84](quantum/bb84.py) * [Deutsch Jozsa](quantum/deutsch_jozsa.py) * [Half Adder](quantum/half_adder.py) * [Not Gate](quantum/not_gate.py) diff --git a/ciphers/atbash.py b/ciphers/atbash.py index 5c2aea610..0a86a800c 100644 --- a/ciphers/atbash.py +++ b/ciphers/atbash.py @@ -38,26 +38,13 @@ def atbash(sequence: str) -> str: def benchmark() -> None: - """Let's benchmark them side-by-side...""" + """Let's benchmark our functions side-by-side...""" from timeit import timeit print("Running performance benchmarks...") - print( - "> atbash_slow()", - timeit( - "atbash_slow(printable)", - setup="from string import printable ; from __main__ import atbash_slow", - ), - "seconds", - ) - print( - "> atbash()", - timeit( - "atbash(printable)", - setup="from string import printable ; from __main__ import atbash", - ), - "seconds", - ) + setup = "from string import printable ; from __main__ import atbash, atbash_slow" + print(f"> atbash_slow(): {timeit('atbash_slow(printable)', setup=setup)} seconds") + print(f"> atbash(): {timeit('atbash(printable)', setup=setup)} seconds") if __name__ == "__main__":