Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve decoding performance #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

steveluscher
Copy link

This yields a performance improvement over indexing into source over and over. source is asserted to be a string, psz is monotonically increasing, and psz >= source.length is a good indication that you've run out of characters.

Originally proposed by @oscxc in #74.

Benchmarks

(cd ../ && npm run build) && SEED=8854dc2a353e143702ef1b29874b63a4 npm start

Before

> base-x-benchmark@0.0.0 start
> node index.js

Seed: 8854dc2a353e143702ef1b29874b63a4
--------------------------------------------------
encode x 389,286 ops/sec ±0.21% (8 runs sampled)
decode x 415,231 ops/sec ±0.91% (9 runs sampled)
==================================================

After

> base-x-benchmark@0.0.0 start
> node index.js

Seed: 8854dc2a353e143702ef1b29874b63a4
--------------------------------------------------
encode x 389,695 ops/sec ±0.12% (9 runs sampled)
decode x 449,877 ops/sec ±0.13% (9 runs sampled)
==================================================

This yields a performance improvement over indexing into `source` over and over. `source` is asserted to be a string, `psz` is monotonically increasing, and `psz >= source.length` is a good indication that you've run out of characters.

Originally proposed by @oscxc in cryptocoinjs#74.

Co-authored-by: Rand <15077550@qq.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.

None yet

1 participant