Skip to content

Instantly share code, notes, and snippets.

@jacaetevha
Created September 27, 2012 14:29
Show Gist options
  • Select an option

  • Save jacaetevha/3794303 to your computer and use it in GitHub Desktop.

Select an option

Save jacaetevha/3794303 to your computer and use it in GitHub Desktop.
Simple currying in Ruby: splat vs. indexed

ruby-1.8.7-p358

Rehearsal -----------------------------------------
splat   0.390000   0.000000   0.390000 (  0.386936)
index   0.770000   0.000000   0.770000 (  0.775964)
-------------------------------- total: 1.160000sec

            user     system      total        real
splat   0.410000   0.000000   0.410000 (  0.407737)
index   0.750000   0.000000   0.750000 (  0.751499)

jruby-1.6.7.2

Rehearsal -----------------------------------------
splat   0.474000   0.000000   0.474000 (  0.236000)
index   0.264000   0.000000   0.264000 (  0.264000)
-------------------------------- total: 0.738000sec

            user     system      total        real
splat   0.067000   0.000000   0.067000 (  0.067000)
index   0.156000   0.000000   0.156000 (  0.156000)

ruby-1.9.3-p194

Rehearsal -----------------------------------------
splat   0.340000   0.000000   0.340000 (  0.349946)
index   0.290000   0.010000   0.300000 (  0.281923)
-------------------------------- total: 0.640000sec

            user     system      total        real
splat   0.330000   0.000000   0.330000 (  0.338157)
index   0.280000   0.000000   0.280000 (  0.285386)

ree-1.8.7-2012.02

Rehearsal -----------------------------------------
splat   0.480000   0.000000   0.480000 (  0.481389)
index   0.790000   0.000000   0.790000 (  0.791499)
-------------------------------- total: 1.270000sec

            user     system      total        real
splat   0.460000   0.000000   0.460000 (  0.458297)
index   0.820000   0.000000   0.820000 (  0.827370)
require 'benchmark'
a = %w{a b c def g hi jklm n op q r stu v wxy z}
n = 1_000_000
Benchmark.bmbm do |x|
x.report("splat"){n.times{head, *tail = a}}
x.report("index"){n.times{head, tail = a[0], a[1..-1]}}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment