Sha256: 3ab21eb4c06b0b53688f650afc71b7d84db5d82ef520284361b10f4cbe9f96ac
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 KB
Contents
require "patternmatching" include PatternMatching class Through def plain(n) n end func(:pattern).seems as {:n} do n end end count = 10000 plain = Through.new start = Time.new count.times do |i| plain.plain(i) end plain_time = Time.new - start pattern = Through.new start = Time.new count.times do |i| pattern.pattern(i) end pattern_time = Time.new - start puts "Check Through call " + count.to_s + " times" puts "Standard Method cost: " + plain_time.to_s + " sec" puts "Partial Method cost: " + pattern_time.to_s + " sec" puts "Overhead/method: " + ((pattern_time - plain_time).to_f / count * 1000).to_s + " msec" puts class Recursive def plain(n) if n > 0 plain(n - 1) end end func(:pattern).seems as {:n}, with {n > 0} do pattern(n-1) end end # size depends on system stack max #count = 600 # for ruby 1.8 stack max #count = 1000 # for ruby 1.9 (200706) stack max #count = 400 # for ruby 1.9 (200606) stack max count = 200 # for jruby1.0 stack max plain = Recursive.new start = Time.new plain.plain(count) plain_time = Time.new - start pattern = Recursive.new start = Time.new pattern.pattern(count) pattern_time = Time.new - start puts "Check Recursive call " + count.to_s + " times" puts "Standard Method cost: " + plain_time.to_s + " sec" puts "Partial Method cost: " + pattern_time.to_s + " sec" puts "Overhead/method: " + ((pattern_time - plain_time).to_f / count * 1000).to_s + " msec" puts
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
patternmatching-0.2.5 | examples/benchmark.rb |