Sha256: f48900bce56391017b3ba09705601ca513faf33b46390e8120eacd72c3676b4b

Contents?: true

Size: 1021 Bytes

Versions: 3

Compression:

Stored size: 1021 Bytes

Contents

require "base64"
require "benchmark/ips"

require "ffi/hydrogen"

require_relative "./init.rb"

def suite(str)
  puts "============================ Test string length: #{str.size} ============================"

  label = "#{str.size}_char"

  encoded = ::FFI::Hydrogen.modp_b64_encode(str)

  Benchmark.ips do |b|
    b.time = 2
    b.warmup = 1

    b.report("modp_b64_encode_#{label}") do |n|
      i = 0
      while i < n
        ::FFI::Hydrogen.modp_b64_encode(str)
        i += 1
      end
    end

    b.report("modp_b64_decode_#{label}") do |n|
      i = 0
      while i < n
        ::FFI::Hydrogen.modp_b64_decode(encoded)
        i += 1
      end
    end

    b.report("base64_encode64_#{label}") do |n|
      i = 0
      while i < n
        ::Base64.encode64(str)
        i += 1
      end
    end

    b.report("base64_decode64_#{label}") do |n|
      i = 0
      while i < n
        ::Base64.decode64(str)
        i += 1
      end
    end

    b.compare!
  end
end

TEST_STRINGS.each do |str|
  suite(str)
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ffi-hydrogen-0.1.2 bench/encode.rb
ffi-hydrogen-0.1.1 bench/encode.rb
ffi-hydrogen-0.1.0 bench/encode.rb