Sha256: b1bbbf77386130417d188ae44d6dd87295f440ec850445d2001d53652719e6ed

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

#!/usr/bin/env ruby

$LOAD_PATH.unshift(File.expand_path('../lib',__FILE__))

require 'hexdump'
require 'benchmark'

class NullOutput
  def <<(data)
  end
end

size_mb = 1
puts "Generating #{size_mb}Mb of random data ..."
data = Array.new(size_mb * 1024 * 1024) { rand(255).chr }.join
output = NullOutput.new

types = Hexdump::TYPES.values.uniq.map(&Hexdump::TYPES.method(:key))

Benchmark.bm(42) do |b|
  b.report('Hexdump.hexdump(data)') do
    Hexdump.hexdump(data, output: output)
  end

  b.report("Hexdump.hexdump(data, repeating: false)") do
    Hexdump.hexdump(data, repeating: false, output: output)
  end

  b.report("Hexdump.hexdump(data, chars_column: false)") do
    Hexdump.hexdump(data, chars_column: false, output: output)
  end

  b.report('Hexdump.hexdump(data, columns: 256)') do
    Hexdump.hexdump(data, columns: 256, output: output)
  end

  b.report('Hexdump.hexdump(data, group_columns: 4)') do
    Hexdump.hexdump(data, group_columns: 4, output: output)
  end

  b.report('Hexdump.hexdump(data, group_chars: 4)') do
    Hexdump.hexdump(data, group_chars: 4, output: output)
  end

  b.report('Hexdump.hexdump(data, encoding: :utf8)') do
    Hexdump.hexdump(data, encoding: :utf8, output: output)
  end

  types.each do |type|
    b.report("Hexdump.hexdump(data, type: #{type.inspect})") do
      Hexdump.hexdump(data, type: type, output: output)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hexdump-1.0.1 benchmark.rb
hexdump-1.0.0 benchmark.rb