🕷 zenspider.com

by ryan davis



sitemap
Looking for the Ruby Quickref?

(Part of) Why I still use ruby 1.8

Published 2011-12-29 @ 14:50

Tagged ruby, thoughts

Check out the time it takes just to start up some of these systems:

1
2
3
4
5
6
7
8
9
10
11
12
13
# # of iterations = 1000
#                                user     system      total        real
# true                       0.030000   0.180000   1.780000 (  2.698916)
# ruby -e 0                  0.040000   0.170000   4.770000 (  6.149741)
# ruby -e 'eval "1 + 1"'     0.030000   0.180000   6.030000 (  6.811871)
# csi -e 0                   0.050000   0.200000   5.720000 (  8.098138)
# perl -e 0                  0.050000   0.200000   6.410000 (  8.193336)
# csi -e eval 1+1 (scheme)   0.050000   0.230000   7.060000 (  8.663545)
# perl -e 'eval "1 + 1"'     0.040000   0.200000   7.580000 (  8.552224)
# ruby193 -e 0               0.050000   0.210000  14.700000 ( 15.981277)
# ruby193 -e 'eval "1 + 1"'  0.060000   0.220000  14.760000 ( 16.010711)
# python -c 0                0.060000   0.280000  46.230000 ( 49.630480)
# python -c 'eval("1 + 1")'  0.060000   0.250000  47.080000 ( 49.251939)

What’s up with python? Still using getc to load all your core libraries? dtruss doesn’t seem to think so but obviously something is going on.

(I think something is wrong with my build of ruby 1.9.3, I’ll look into it)

From:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'benchmark'

MAX = (ARGV.shift || 1_000).to_i

puts "# of iterations = #{MAX}"
Benchmark::bm(25) do |x|
  def x.go cmd, name=cmd
    report name do
      for i in 0..MAX do
        system cmd
      end
    end
  end

  ruby18 = "~/.multiruby/install/1.8.7-p330/bin/ruby"
  ruby18 = "ruby"
  ruby19 = "~/.multiruby/install/1.9.3-p0/bin/ruby --disable-gems"
  csi_code = "csi -e '(eval (with-input-from-string \"(+ 1 1)\" read))'"

  x.go "true"
  x.go "#{ruby18} -e 0",                "ruby187 -e 0"
  x.go "#{ruby18} -e 'eval \"1 + 1\"'", "ruby187 -e 'eval \"1 + 1\"'"
  x.go "csi -e 0"
  x.go "perl -e 0"
  x.go csi_code,                        "csi -e eval 1+1 (scheme)"
  x.go "perl -e 'eval \"1 + 1\"'"
  x.go "#{ruby19} -e 0",                "ruby193 -e 0"
  x.go "#{ruby19} -e 'eval \"1 + 1\"'", "ruby193 -e 'eval \"1 + 1\"'"
  x.go "python -c 0"
  x.go "python -c 'eval(\"1 + 1\")'"
end