Rakefile in sig-1.0.1 vs Rakefile in sig-1.0.2
- old
+ new
@@ -33,121 +33,11 @@
# # #
# Benchmark: Take with a grain of salt
desc "Compare with contracts and rubype"
task :benchmark do
- require "benchmark/ips"
- require "rubype"
- require "rubype/version"
- require "contracts"
- require "contracts/version"
- require_relative "lib/sig"
-
- # - - -
-
- class PureSum
- def sum(x, y)
- x + y
- end
-
- def mul(x, y)
- x * y
- end
- end
- pure_instance = PureSum.new
- puts "ruby version: #{RUBY_VERSION}"
-
- # - - -
-
- class SigSum
- sig [Numeric, Numeric], Numeric,
- def sum(x, y)
- x + y
- end
-
- sig [:to_i, :to_i], Numeric,
- def mul(x, y)
- x * y
- end
- end
- sig_instance = SigSum.new
- puts "sig version: #{Sig::VERSION}"
-
- # - - -
-
- class RubypeSum
- def sum(x, y)
- x + y
- end
- typesig :sum, [Numeric, Numeric] => Numeric
-
- def mul(x, y)
- x * y
- end
- typesig :mul, [:to_i, :to_i] => Numeric
- end
- rubype_instance = RubypeSum.new
- puts "rubype version: #{Rubype::VERSION}"
-
- # - - -
-
- class ContractsSum
- include Contracts
-
- Contract Num, Num => Num
- def sum(x, y)
- x + y
- end
-
- Contract RespondTo[:to_i], RespondTo[:to_i] => Num
- def mul(x, y)
- x * y
- end
- end
- contracts_instance = ContractsSum.new
- puts "contracts version: #{Contracts::VERSION}"
-
- Benchmark.ips do |x|
- x.report("pure"){ |times|
- i = 0
- while i < times
- pure_instance.sum(1, 2)
- pure_instance.mul(1, 2)
- i += 1
- end
- }
-
- x.report("sig"){ |times|
- i = 0
- while i < times
- sig_instance.sum(1, 2)
- sig_instance.mul(1, 2)
- i += 1
- end
- }
-
- x.report("rubype"){ |times|
- i = 0
- while i < times
- rubype_instance.sum(1, 2)
- rubype_instance.mul(1, 2)
- i += 1
- end
- }
-
- x.report("contracts"){ |times|
- i = 0
- while i < times
- contracts_instance.sum(1, 2)
- contracts_instance.mul(1, 2)
- i += 1
- end
- }
-
- x.compare!
- end
+ ruby "benchmark/compare.rb"
end
-
# # #
# Specs
desc "Run specs"