The Wayback Machine - https://web.archive.org/web/20260515232306/https://github.com/TheAlgorithms/Python/pull/2017
Skip to content

Update atbash cipher (doc, doctest, performance)#2017

Merged
cclauss merged 3 commits into
TheAlgorithms:masterfrom
l3str4nge:update_atbash
May 20, 2020
Merged

Update atbash cipher (doc, doctest, performance)#2017
cclauss merged 3 commits into
TheAlgorithms:masterfrom
l3str4nge:update_atbash

Conversation

@l3str4nge
Copy link
Copy Markdown
Member

Describe your change:

Added update for atbash cipher:

  • doctests,
  • type hints
  • little performance improvement
  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Copy link
Copy Markdown
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running performance benchmarks...
> atbash_slow() 18.921338292999998 seconds
>      atbash() 16.922152821999997 seconds

How could atbash() be modified to be much faster?

@cclauss cclauss merged commit 965d02a into TheAlgorithms:master May 20, 2020
@l3str4nge
Copy link
Copy Markdown
Member Author

With small string speed is not visible - even worse. I've tried with 4 000 000 characters length and current implementation is little bit faster (from 3.2 sec -> 2.2 - 2.4 sec). That's why I wrote "little" in PR description :)

I can put some performance tests I made If you want :)

@l3str4nge
Copy link
Copy Markdown
Member Author

Running performance benchmarks...
> atbash_slow() 18.921338292999998 seconds
>      atbash() 16.922152821999997 seconds

How could atbash() be modified to be much faster?

I thought about modulo operations and remove completely searching characters in ascii_letters. If statement in list comprehensions slowing down too. For now I don't have idea but I know it's possible :)

@cclauss
Copy link
Copy Markdown
Member

cclauss commented May 20, 2020

Would it help if we moved the definition of letters and letters_reversed outside the function?

@l3str4nge
Copy link
Copy Markdown
Member Author

Would it help if we moved the definition of letters and letters_reversed outside the function?

Perhaps but insignifficant, these strings are too small. The bottleneck is here:
.. letters.index(c) .. if c in letters else c. ..

stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Update atbash

* Add benchmark() to quantify the performance improvement

Co-authored-by: Christian Clauss <cclauss@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

HTTPS · web.archive.org
← Home