Skip to content

Instantly share code, notes, and snippets.

@rtyler
Created October 26, 2014 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtyler/300c271a9634d62c0212 to your computer and use it in GitHub Desktop.
Save rtyler/300c271a9634d62c0212 to your computer and use it in GitHub Desktop.
[15:39:26] tyler:typedeaf git:(master*) $ ruby benchmarks/parameter_calls.rb
Go?
Calculating -------------------------------------
typedeaf method 347 i/100ms
normal method 8275 i/100ms
a simple proc 18289 i/100ms
-------------------------------------------------
typedeaf method 336224.8 (±15.4%) i/s - 862295 in 3.809999s
normal method 8204901.8 (±7.6%) i/s - 14340575 in 1.900007s
a simple proc 17884419.2 (±13.1%) i/s - 26756807 in 2.743001s
Comparison:
a simple proc: 17884419.2 i/s
normal method: 8204901.8 i/s - 2.18x slower
typedeaf method: 336224.8 i/s - 53.19x slower
Go?
Calculating -------------------------------------
typedeaf method 2875 i/100ms
normal method 18793 i/100ms
a simple proc 26690 i/100ms
-------------------------------------------------
typedeaf method 2846897.2 (±8.3%) i/s - 8964250 in 3.491001s
normal method 18724278.3 (±4.9%) i/s - 31703791 in 1.753998s
a simple proc 26510489.4 (±6.5%) i/s - 44572300 in 1.806992s
Comparison:
a simple proc: 26510489.4 i/s
normal method: 18724278.3 i/s - 1.42x slower
typedeaf method: 2846897.2 i/s - 9.31x slower
Go?
Calculating -------------------------------------
typedeaf method 3718 i/100ms
normal method 25648 i/100ms
a simple proc 23469 i/100ms
-------------------------------------------------
typedeaf method 3681971.8 (±8.2%) i/s - 10856560 in 3.391997s
normal method 25457201.0 (±6.8%) i/s - 43345120 in 1.736006s
a simple proc 23346896.5 (±5.9%) i/s - 41821758 in 1.833998s
Comparison:
normal method: 25457201.0 i/s
a simple proc: 23346896.5 i/s - 1.09x slower
typedeaf method: 3681971.8 i/s - 6.91x slower
Go?
Calculating -------------------------------------
typedeaf method 5103 i/100ms
normal method 27352 i/100ms
a simple proc 26048 i/100ms
-------------------------------------------------
typedeaf method 5058548.1 (±7.7%) i/s - 15972390 in 3.406994s
normal method 27103909.3 (±7.8%) i/s - 45376968 in 1.774999s
a simple proc 25842187.1 (±7.3%) i/s - 44203456 in 1.788002s
Comparison:
normal method: 27103909.3 i/s
a simple proc: 25842187.1 i/s - 1.05x slower
typedeaf method: 5058548.1 i/s - 5.36x slower
Go?
[15:43:27] tyler:typedeaf git:(master*) $ ruby benchmarks/parameter_calls.rb
Compiled extensions not installed, pure Ruby Atomic will be used.
Go?
Calculating -------------------------------------
typedeaf method 5107 i/100ms
normal method 20486 i/100ms
a simple proc 18832 i/100ms
-------------------------------------------------
typedeaf method 350793220.6 (±25.4%) i/s - 661867200 in 2.804116s
normal method 6557401501.9 (±26.4%) i/s - 5107303202 in 1.060535s
a simple proc 5718224483.2 (±28.8%) i/s - 4892647760 in 1.172734s
Comparison:
normal method: 6557401501.9 i/s
a simple proc: 5718224483.2 i/s - 1.15x slower
typedeaf method: 350793220.6 i/s - 18.69x slower
Go?
Calculating -------------------------------------
typedeaf method 5864 i/100ms
normal method 20307 i/100ms
a simple proc 19743 i/100ms
-------------------------------------------------
typedeaf method 402393116.0 (±23.0%) i/s - 823170728 in 2.927404s
normal method 6433378450.7 (±27.5%) i/s - 5219548824 in 1.141299s
a simple proc 6120762652.6 (±26.7%) i/s - 5237541498 in 1.139145s
Comparison:
normal method: 6433378450.7 i/s
a simple proc: 6120762652.6 i/s - 1.05x slower
typedeaf method: 402393116.0 i/s - 15.99x slower
Go?
Calculating -------------------------------------
typedeaf method 5224 i/100ms
normal method 21435 i/100ms
a simple proc 17738 i/100ms
-------------------------------------------------
typedeaf method 357069139.7 (±23.3%) i/s - 732645104 in 2.959491s
normal method 6804555423.6 (±27.8%) i/s - 5343895545 in 1.116959s
a simple proc 5414431774.7 (±29.7%) i/s - 4425861594 in 1.152911s
Comparison:
normal method: 6804555423.6 i/s
a simple proc: 5414431774.7 i/s - 1.26x slower
typedeaf method: 357069139.7 i/s - 19.06x slower
Go?
Calculating -------------------------------------
typedeaf method 5002 i/100ms
normal method 22220 i/100ms
a simple proc 21331 i/100ms
-------------------------------------------------
typedeaf method 342156096.1 (±23.1%) i/s - 683598330 in 3.021058s
normal method 7077451236.2 (±27.0%) i/s - 5696319200 in 1.187232s
a simple proc 6487474366.3 (±29.0%) i/s - 5673875352 in 1.197232s
Comparison:
normal method: 7077451236.2 i/s
a simple proc: 6487474366.3 i/s - 1.09x slower
typedeaf method: 342156096.1 i/s - 20.68x slower
Go?
require_relative 'bench_helper'
class Parametered
include Typedeaf
def method_with_params(buffer)
buffer.size
end
define :typedeaf_with_params, buffer: String do
buffer.size
end
end
blk = Proc.new do |buffer|
buffer.size
end
p = Parametered.new
loop do
puts 'Go?'
STDIN.getc
Benchmark.ips do |x|
x.report('typedeaf method') { |i| p.typedeaf_with_params(i.to_s) }
x.report('normal method') { |i| p.method_with_params(i.to_s) }
x.report('a simple proc') { |i| blk.(i.to_s) }
x.compare!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment