From 5d2376a1e7b989f1e36aec4386c7a4c8b03c7642 Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Sun, 26 Oct 2014 17:22:56 -0700 Subject: [PATCH] Add a benchmark and results for method calls with missing arguments --- benchmarks/missing_arguments.rb | 27 +++++++++++++++++++++++++++ benchmarks/missing_arguments.txt | 15 +++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 benchmarks/missing_arguments.rb create mode 100644 benchmarks/missing_arguments.txt diff --git a/benchmarks/missing_arguments.rb b/benchmarks/missing_arguments.rb new file mode 100644 index 0000000..80056ac --- /dev/null +++ b/benchmarks/missing_arguments.rb @@ -0,0 +1,27 @@ +require_relative 'bench_helper' + +class MissingArgs + include Typedeaf + + def method_with_params(buffer) + buffer.size + rand + rand + end + + define :typedeaf_with_params, buffer: String do + buffer.size + rand + rand + end +end + +blk = lambda do |buffer| + buffer.size + rand + rand +end + +p = MissingArgs.new + + +Benchmark.ips do |x| + x.report('typedeaf method') { begin; p.typedeaf_with_params; rescue; end; } + x.report('normal method') { begin; p.method_with_params; rescue; end; } + x.report('a simple proc') { begin; blk.(); rescue; end; } + x.compare! +end diff --git a/benchmarks/missing_arguments.txt b/benchmarks/missing_arguments.txt new file mode 100644 index 0000000..45b5b36 --- /dev/null +++ b/benchmarks/missing_arguments.txt @@ -0,0 +1,15 @@ +As of: 790130d + +Calculating ------------------------------------- + typedeaf method 2292 i/100ms + normal method 2889 i/100ms + a simple proc 2594 i/100ms +------------------------------------------------- + typedeaf method 27691.2 (±12.6%) i/s - 137520 in 5.057106s + normal method 34595.8 (±12.9%) i/s - 170451 in 5.028954s + a simple proc 31650.1 (±15.4%) i/s - 155640 in 5.058063s + +Comparison: + normal method: 34595.8 i/s + a simple proc: 31650.1 i/s - 1.09x slower + typedeaf method: 27691.2 i/s - 1.25x slower