Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "benchmark"
- require 'base64'
- TESTS = 1_000_000
- STRING = ('a'..'z').to_a.join
- puts "# #{TESTS} iterations"
- puts "# Data: #{STRING}"
- Benchmark.bmbm do |results|
- results.report('base64') do
- TESTS.times do
- Base64.encode64(STRING)
- end
- end
- results.report('pack') do
- TESTS.times do
- [STRING].pack('m')
- end
- end
- end
- # # 1000000 iterations
- # # Data: abcdefghijklmnopqrstuvwxyz
- # Rehearsal ------------------------------------------
- # base64 1.300000 0.010000 1.310000 ( 1.323245)
- # pack 1.040000 0.000000 1.040000 ( 1.035519)
- # --------------------------------- total: 2.350000sec
- #
- # user system total real
- # base64 1.290000 0.010000 1.300000 ( 1.299331)
- # pack 1.040000 0.000000 1.040000 ( 1.042376)
Add Comment
Please, Sign In to add comment