Skip to content

Instantly share code, notes, and snippets.

@slyphon
Created December 1, 2009 04:20
Show Gist options
  • Save slyphon/246049 to your computer and use it in GitHub Desktop.
Save slyphon/246049 to your computer and use it in GitHub Desktop.
#!/usr/bin/env jruby
require 'benchmark'
require 'base64'
ALNUMS = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
ITER = 100_000
blob = []
100.times do |n|
blob += ALNUMS.shuffle
end
blob = blob.join('')
b64_encoded_blob = Base64.encode64(blob)
$stderr.puts "blob length: #{blob.length}"
Benchmark.bmbm do |x|
x.report('Base64.encode64') { ITER.times { Base64.encode64(blob) } }
x.report('Base64.decode64') { ITER.times { Base64.decode64(b64_encoded_blob) } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment