File: for_vs_array_each.rb

package info (click to toggle)
ruby-excon 0.112.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,232 kB
  • sloc: ruby: 7,855; makefile: 5
file content (27 lines) | stat: -rw-r--r-- 492 bytes parent folder | download | duplicates (7)
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
require 'rubygems'
require 'tach'

data = ["some", "var", "goes", "in", :here, 0]
Tach.meter(1_000_000) do
  tach('for') do
    for element in data
      element == nil
    end
  end
  tach('each') do
    data.each do |element|
      element == nil
    end
  end
end

# ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
# 
# +------+----------+
# | tach | total    |
# +------+----------+
# | for  | 2.958672 |
# +------+----------+
# | each | 2.983550 |
# +------+----------+
#