Sha256: af37441e8a57f85ed687f4aea265f9a4d237c5ff53dd5c81a3d36686a17d631d

Contents?: true

Size: 1.31 KB

Versions: 36

Compression:

Stored size: 1.31 KB

Contents

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

include Contracts

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

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

@urls = %w{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

36 entries across 26 versions & 7 rubygems

Version Path
entitlements-app-1.2.0 lib/contracts-ruby3/benchmarks/io.rb
entitlements-app-1.2.0 lib/contracts-ruby2/benchmarks/io.rb
contracts-0.17.2 benchmarks/io.rb
contracts-0.17.1 benchmarks/io.rb
entitlements-app-1.1.0 lib/contracts-ruby2/benchmarks/io.rb
entitlements-app-1.1.0 lib/contracts-ruby3/benchmarks/io.rb
entitlements-app-1.0.0 lib/contracts-ruby3/benchmarks/io.rb
entitlements-app-1.0.0 lib/contracts-ruby2/benchmarks/io.rb
entitlements-app-0.3.4 lib/contracts-ruby3/benchmarks/io.rb
entitlements-app-0.3.4 lib/contracts-ruby2/benchmarks/io.rb
entitlements-app-0.3.1 lib/contracts-ruby3/benchmarks/io.rb
entitlements-app-0.3.1 lib/contracts-ruby2/benchmarks/io.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/contracts-0.17/benchmarks/io.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/contracts-0.17/benchmarks/io.rb
entitlements-app-0.3.0 lib/contracts-ruby2/benchmarks/io.rb
entitlements-app-0.3.0 lib/contracts-ruby3/benchmarks/io.rb
entitlements-0.2.1 lib/contracts-ruby2/benchmarks/io.rb
entitlements-0.2.1 lib/contracts-ruby3/benchmarks/io.rb
entitlements-app-0.2.1 lib/contracts-ruby2/benchmarks/io.rb
entitlements-app-0.2.1 lib/contracts-ruby3/benchmarks/io.rb