Sha256: 65a0ca52eeda1a042326e52717c95236d2ae7da7bc27914b9336719a50696a50

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

#require 'rubygems'; gem 'bindata'

require 'bindata'

COUNT = 50000

Test1 = Struct.new(:a, :b, :c)

class Test2
  attr_accessor :a, :b, :c
end

class Test3
  def initialize
    @a = @b = @c = 1
  end

  def a=(v)
    @a = v
  end
  def b=(v)
    @b = v
  end
  def c=(v)
    @c = v
  end
end

class Test4 < BinData::Record
  endian :little

  int8 :a
  int8 :b
  int8 :c
end

def test1(klass)
  a  = Time.now
    z = []
    COUNT.times do
      obj = klass.new
#      obj.a = 1
#      obj.b = 1
#      obj.c = 1
      z << obj
    end
  b = Time.now
  puts "#{klass}: #{b - a}"
end

def test2
  a  = Time.now
    z = []
    COUNT.times do |i|
      eval <<-END
      class A#{i} < BinData::Record
        int8 :a
        int8 :b
        int8 :c
        int8 :d
        int8 :e
        int8 :f
        int8 :g
        int8 :h
        int8 :i
        int8 :j
        int8 :k
        int8 :l
        int8 :m
        int8 :n
        int8 :o
        int8 :p
        int8 :q
        int8 :r
        int8 :s
        int8 :t
      end
      END
    end
  b = Time.now
  puts "test2: #{b - a}"
end


def prof(&block)
  require 'rubygems'
  require 'ruby-prof'
  result = RubyProf.profile do
    block.call
  end

  printer = RubyProf::GraphPrinter.new(result)
  printer.print(STDOUT, 0)
end


#test1(Test1)
#test1(Test2)
#test1(Test3)
test1(Test4)

#test2

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bindata-1.2.1 lib/bench.rb