Sha256: eab412e1bf6c43a9f7f9c848b68ebd9338a4d33da6d8dc2e301cb394c4103596

Contents?: true

Size: 933 Bytes

Versions: 6

Compression:

Stored size: 933 Bytes

Contents

require 'benchmark'
require '../lib/gamebox'

class BoxedActor
  include Kvo
  kvo_attr_accessor :x, :y
  attr_accessor :w, :h

  can_fire_anything

  def initialize(x,y,w,h)
    @kvo_x = x
    @kvo_y = y
    @w = w
    @h = h
  end

  def bb
    @bb ||= Rect.new(x,y,w,h)
  end

end
# require 'perftools'
# PerfTools::CpuProfiler.start("/tmp/perf.txt")


NUM = 1_000
Benchmark.bm(60) do |b|
  b.report("full") do
    tree = SpatialTree.new :thing

    thing = BoxedActor.new 1, 2, 3, 4
    tree.add thing
    things = []
    100.times do |i|
      t = BoxedActor.new i, i, i, i
      things << t
      tree.add t
    end

    NUM.times do 
      it = BoxedActor.new 1, 2, 3, 4
      tree.add it

      thing.x + 1
      things[20..40].each do |t|
        t.x += rand(40)-20
      end

      tree.query thing.bb do
      end

      tree.remove it
    end
  end
end

# PerfTools::CpuProfiler.stop
# be pprof.rb --text /tmp/perf.txt


Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gamebox-0.5.5 script/perf_aabb.rb
gamebox-0.5.4 script/perf_aabb.rb
gamebox-0.5.2 script/perf_aabb.rb
gamebox-0.5.1 script/perf_aabb.rb
gamebox-0.5.0 script/perf_aabb.rb
gamebox-0.4.1 script/perf_aabb.rb