Rakefile in sig-1.0.0 vs Rakefile in sig-1.0.1

- old
+ new

@@ -27,10 +27,11 @@ desc "#{gemspec.name} | IRB" task :irb do sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}" end + # # # # Benchmark: Take with a grain of salt desc "Compare with contracts and rubype" task :benchmark do @@ -61,11 +62,11 @@ sig [Numeric, Numeric], Numeric, def sum(x, y) x + y end - sig [Numeric, Numeric], Numeric, + sig [:to_i, :to_i], Numeric, def mul(x, y) x * y end end sig_instance = SigSum.new @@ -80,11 +81,11 @@ typesig :sum, [Numeric, Numeric] => Numeric def mul(x, y) x * y end - typesig :mul, [Numeric, Numeric] => Numeric + typesig :mul, [:to_i, :to_i] => Numeric end rubype_instance = RubypeSum.new puts "rubype version: #{Rubype::VERSION}" # - - - @@ -95,44 +96,62 @@ Contract Num, Num => Num def sum(x, y) x + y end - Contract Num, Num => Num + 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"){ - pure_instance.sum(1, 2) - pure_instance.mul(1, 2) + 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"){ - sig_instance.sum(1, 2) - sig_instance.mul(1, 2) + 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"){ - rubype_instance.sum(1, 2) - rubype_instance.mul(1, 2) + 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"){ - contracts_instance.sum(1, 2) - contracts_instance.mul(1, 2) + x.report("contracts"){ |times| + i = 0 + while i < times + contracts_instance.sum(1, 2) + contracts_instance.mul(1, 2) + i += 1 + end } - x.warmup = 10 + x.compare! end end + # # # # Specs + desc "Run specs" task :spec do ruby "spec/sig_spec.rb" end task default: :spec