Sha256: b71879a08d3038405a820824b4e698f6bb24f9a00782311e4bc74452e8e05d91

Contents?: true

Size: 462 Bytes

Versions: 13

Compression:

Stored size: 462 Bytes

Contents

require 'benchmark'

# Point = Struct.new :x, :y
# class Point
#   attr_accessor :x, :y
#   def initialize(x,y)
#     @x = x
#     @y = y
#   end
# end
NUM = 10_000_000
Benchmark.bm(60) do |b|
  b.report("array") do
    NUM.times do 
      it = [4,6]
      it[0] = 1
      it[1] = 3
      it[0]
      it[1]
    end
  end
  b.report("struct") do
    NUM.times do 
      it = Point.new 4, 6
      it.x = 1
      it.y = 3
      it.x 
      it.y 
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
gamebox-0.5.5 script/perf_struct_vs_array.rb
gamebox-0.5.4 script/perf_struct_vs_array.rb
gamebox-0.5.2 script/perf_struct_vs_array.rb
gamebox-0.5.1 script/perf_struct_vs_array.rb
gamebox-0.5.0 script/perf_struct_vs_array.rb
gamebox-0.4.1 script/perf_struct_vs_array.rb
gamebox-0.4.0 script/perf_struct_vs_array.rb
gamebox-0.4.0.rc11 script/perf_struct_vs_array.rb
gamebox-0.4.0.rc5 script/perf_struct_vs_array.rb
gamebox-0.4.0.rc4 script/perf_struct_vs_array.rb
gamebox-0.4.0.rc3 script/perf_struct_vs_array.rb
gamebox-0.4.0.rc2 script/perf_struct_vs_array.rb
gamebox-0.4.0.rc1 script/perf_struct_vs_array.rb