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

speed improvement for bs58.encode() #10

Merged
merged 1 commit into from
Dec 23, 2014

Conversation

RainaBatwing
Copy link
Contributor

With this change, bs58.encode with 32-digit input runs in about 80% the time the previous version took.

With this change, bs58.encode with 32-digit input runs in about 80% the time the previous version took.
@jprichardson
Copy link
Member

It'd be nice to see actual numbers, but I'd imagine that you're probably right with most modern JITs.

jprichardson added a commit that referenced this pull request Dec 23, 2014
speed improvement for bs58.encode()
@jprichardson jprichardson merged commit 7d4a5d6 into cryptocoinjs:master Dec 23, 2014
@RainaBatwing
Copy link
Contributor Author

Thank you for accepting my pull! I'm glad I could contribute. Here are the actual numbers from my little old laptop:

$ coffee bench.coffee
bs58: 1672ms
bs58o: 1394ms
bs58: 1667ms
bs58o: 1395ms

bench.coffee is below. I had my modified version of the library in ./node_modules/bs58-0 and the then current version in ./node_modules/bs58. The script repeats the test a few times to try and get V8 nice and warmed up. The results seem pretty consistent. I tried a few different ways of building the string, including preallocating arrays and things, but this was the quickest!

bs58 = require './node_modules/bs58'
bs58o = require './node_modules/bs58-o'

cycles = 50000
# create test input - 32 bytes
test = (x for x in [0..32])

# warm up the code paths in V8
for i in [0...10000]
  bs58.encode(test)
  bs58o.encode(test)

bs58r = null
bs58or = null
console.time('bs58')
for i in [0...cycles]
  bs58r = bs58.encode(test)
console.timeEnd('bs58')

console.time('bs58o')
for i in [0...cycles]
  bs58or = bs58o.encode(test)
console.timeEnd('bs58o')

console.time('bs58')
for i in [0...cycles]
  bs58r = bs58.encode(test)
console.timeEnd('bs58')

console.time('bs58o')
for i in [0...cycles]
  bs58or = bs58o.encode(test)
console.timeEnd('bs58o')

if bs58r != bs58or
  console.log("outputs do not match!", bs58r, bs58or)

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