Sha256: 378b77f7ee05ba31039f1b8a92ec5cc1e647bc10291e544b4a879fb885a80069

Contents?: true

Size: 856 Bytes

Versions: 2

Compression:

Stored size: 856 Bytes

Contents

#! /usr/bin/env ruby

lib = File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require 'list'
require 'benchmark'

Benchmark.bm(32) do |x|
  [100000].each do |n|
    x.report("#{n}times") do
      n.times do
      end
    end
  end

  [Array, List].each do |obj|
    [100000].each do |n|
      x.report("#{obj}#new #{n}times") do
        n.times do
          obj.new
        end
      end
    end
  end

  [[:[], 100000], [:push, 1], [:unshift, 1], [:pop], [:shift], [:insert, 0, 1], [:delete_at, 0]].each do |args|
    m = args.shift
    [(0..100000).to_a, (0..100000).to_list].each do |obj|
      [100000].each do |n|
        o = obj.dup
        x.report("#{o.class}##{m} #{n}times") do
          n.times do
            o.send(m, *args)
          end
        end
        GC.start
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
list-0.2.0 spec/bench.rb
list-0.1.0 spec/bench.rb