= 100 def create_people(people_count); end def report; end def simulate_to(count) 1.upto(count) {|i| yield i } end people = create_people(PEOPLE_COUNT) simulate_to(SIMULATION_LENGTH) do |iteration| # mish and mash people end report
current_pairs(iteration).each{|pair| pair.contact(iteration)} end end class Pair def contact(iteration) @alpha.infect(iteration, @beta) @beta.infect(iteration, @alpha) end end class Person def infect(iteration, person); end def acquire(infection); end end
@infections.each do |infection| if rand <= infection.chance_to_acquire_disease unless has_disease? infection.disease @diseases << infection.disease.new(iteration) end end end end end
can't convert Range into Integer " from org/jruby/RubyKernel.java:1580:in `rand' " from (irb):3:in `evaluate' " from org/jruby/RubyKernel.java:1070:in `eval' " from org/jruby/RubyKernel.java:1395:in `loop' " from org/jruby/RubyKernel.java:1178:in `catch' " from org/jruby/RubyKernel.java:1178:in `catch' " from /Users/bryan/.rbenv/versions/jruby-1.7.0-preview2/bin/irb:13:in `(root)' JRuby 1.7 pre2
n,m = [1_000_000, 100] Benchmark.bm do |x| x.report do m.times do a = []; n.times{|i| a[i] = i}; n.times{ j=a[rand(n)]; j*j} end end x.report do m.times do h = {}; n.times{|i| h[i] = i}; n.times{j=h[rand(n)]; j*j} end end end
big_arrays.rb user system total real 41.920000 0.330000 42.250000 ( 42.258538) 138.270000 2.860000 141.130000 (141.366728) [~/Development/talks/arrrrcamp2012/src/lib] -> ♢ % ruby big_arrays.rb user system total real 88.320000 0.570000 88.890000 ( 41.623000) 191.970000 0.460000 192.430000 ( 73.113000) [~/Development/talks/arrrrcamp2012/src/lib]
discrete.rb 36500 1000 creating 1000 people inoculating 50% of the population circle circle dot dot. now you have a cootie shot starting simulation 3650 7300 10950 14600 18250 21900 25550 29200 32850 36500 runtime: 129.49060773849487 Infected: 479 Noninfected: 521
discrete.rb 36500 1000 creating 1000 people inoculating 50% of the population circle circle dot dot. now you have a cootie shot starting simulation 3650 7300 10950 14600 18250 21900 25550 29200 32850 36500 runtime: 129.88899993896484 Infected: 526 Noninfected: 474
<< event def do_step(current_step) current_events = event_pool.find_all do |event| event.on?(current_step) end current_events.each do |event| event.run event_pool << event.schedule end end