Created
February 1, 2015 17:26
-
-
Save PJK/cdd4de5092eb828ea002 to your computer and use it in GitHub Desktop.
contracts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler' | |
Bundler.require | |
include Contracts | |
Contract Num, Num => Num | |
def add_c(a, b) | |
a + b | |
end | |
def add(a, b) | |
a + b | |
end | |
Benchmark.ips do |_| | |
_.report('contract') { add_c(3, 4) } | |
_.report('no contract') { add(3, 4) } | |
_.compare! | |
end | |
# pavel@dt3:~/prizeo/contract|⇒ bundle exec ruby add.rb | |
# Calculating ------------------------------------- | |
# contract 22.437k i/100ms | |
# no contract 116.177k i/100ms | |
# ------------------------------------------------- | |
# contract 282.640k (± 4.5%) i/s - 1.414M | |
# no contract 6.450M (± 8.6%) i/s - 32.065M | |
# | |
# Comparison: | |
# no contract: 6450153.1 i/s | |
# contract: 282640.5 i/s - 22.82x slower | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment