Sha256: adf64cc1038284a3cc7d6e52aafb23f68dce163430b09ac79085083d2a023a30
Contents?: true
Size: 1.27 KB
Versions: 2
Compression:
Stored size: 1.27 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" 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 count = 300 # depends on system stack size 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"
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
patternmatching-0.2.2 | examples/overhead.rb |
patternmatching-0.2.3 | examples/overhead.rb |