Sha256: 8922070a01fb733501cf3ebaef7773c2bda2a1524f3be23e5f87584d4eda5ba7
Contents?: true
Size: 895 Bytes
Versions: 4
Compression:
Stored size: 895 Bytes
Contents
$:.unshift "../lib" require 'benchmark' require 'needle' ITERATIONS = 100_000 S = Struct.new( :value ) registry = Needle::Registry.new registry.register( :immediate, :model=>:prototype ) { S.new } registry.register( :deferred, :model=>:prototype_deferred ) { S.new } puts puts "--------------------------------------------------------------------" puts "Direct vs. Immediate vs. Deferred instantiation (trivial)" puts "#{ITERATIONS} iterations" puts Benchmark.bm(10) do |x| GC.disable x.report( "direct:" ) { ITERATIONS.times { S.new } } GC.start x.report( "immediate:" ) { ITERATIONS.times { registry.immediate } } GC.start x.report( "deferred:" ) { ITERATIONS.times { registry.deferred } } GC.start x.report( "deferred*:" ) { ITERATIONS.times { registry.deferred.value } } GC.enable end puts "* this benchmark forced the proxy to instantiate its wrapped service" puts
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
needle-0.6.0 | benchmarks/instantiation.rb |
needle-0.9.0 | benchmarks/instantiation.rb |
needle-1.0.0 | benchmarks/instantiation.rb |
needle-1.1.0 | benchmarks/instantiation.rb |