benchmark.rb in ob64-0.1.0 vs benchmark.rb in ob64-0.2.0

- old
+ new

@@ -2,10 +2,15 @@ require "securerandom" require "ob64" require "base64" +$run_encode_benchmark = false +$run_decode_benchmark = false +$run_urlsafe_encode_benchmark = false +$run_urlsafe_decode_benchmark = true + def to_size(bytes) bytes >= 2**20 ? "#{bytes / 2**20} MB" : "#{bytes / 2**10} kB" end def each_block @@ -57,11 +62,11 @@ Ob64.encode($unencoded) end x.compare! end -end +end if $run_encode_benchmark decode_benchmark do Benchmark.ips do |x| x.time = 5 x.warmup = 2 @@ -69,11 +74,45 @@ x.report("base64 .strict_decode64") do Base64.strict_decode64($encoded) end x.report("ob64 .decode") do - Ob64.encode($encoded) + Ob64.decode($encoded) end x.compare! end -end +end if $run_decode_benchmark + +encode_benchmark do + Benchmark.ips do |x| + x.time = 5 + x.warmup = 2 + + x.report("base64 .urlsafe_encode64") do + Base64.urlsafe_encode64($unencoded) + end + + x.report("ob64 .urlsafe_encode") do + Ob64.urlsafe_encode($unencoded) + end + + x.compare! + end +end if $run_urlsafe_encode_benchmark + +decode_benchmark do + Benchmark.ips do |x| + x.time = 5 + x.warmup = 2 + + x.report("base64 .urlsafe_decode64") do + Base64.urlsafe_decode64($encoded) + end + + x.report("ob64 .urlsafe_decode") do + Ob64.urlsafe_decode($encoded) + end + + x.compare! + end +end if $run_urlsafe_decode_benchmark