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>
This commit is contained in:
Christian Clauss 2022-11-10 03:41:28 +01:00 committed by GitHub
parent 076193eefa
commit 4cddb26908
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 17 deletions

View File

@ -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)

View File

@ -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__":