Sha256: dbe097cb4c5595f217778b9efab00eefb90b73bd79cec3ada73f1d49bae02c03

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

require "./lib/contracts"
require "benchmark"
require "rubygems"
require "method_profiler"
require "ruby-prof"
require "open-uri"

include Contracts

def download url
  open("https://www.#{url}/").read
end

Contract String => String
def contracts_download url
  open("https://www.#{url}").read
end

@urls = %w{facebook.com google.com bing.com}

def benchmark
  Benchmark.bm 30 do |x|
    x.report "testing download" do
      100.times do |_|
        download(@urls.sample)
      end
    end
    x.report "testing contracts download" do
      100.times do |_|
        contracts_download(@urls.sample)
      end
    end
  end
end

def profile
  profilers = []
  profilers << MethodProfiler.observe(Contract)
  profilers << MethodProfiler.observe(Object)
  profilers << MethodProfiler.observe(Contracts::MethodDecorators)
  profilers << MethodProfiler.observe(Contracts::Decorator)
  profilers << MethodProfiler.observe(Contracts::Support)
  profilers << MethodProfiler.observe(UnboundMethod)
  10.times do |_|
    contracts_download(@urls.sample)
  end
  profilers.each { |p| puts p.report }
end

def ruby_prof
  RubyProf.start
  10.times do |_|
    contracts_download(@urls.sample)
  end
  result = RubyProf.stop
  printer = RubyProf::FlatPrinter.new(result)
  printer.print(STDOUT)
end

benchmark
profile
ruby_prof if ENV["FULL_BENCH"] # takes some time

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
contracts-0.11.0 benchmarks/io.rb
contracts-0.10.1 benchmarks/io.rb
contracts-0.10 benchmarks/io.rb
contracts-0.9 benchmarks/io.rb
contracts-0.8 benchmarks/io.rb