~ubuntu-branches/ubuntu/utopic/ruby-excon/utopic

« back to all changes in this revision

Viewing changes to benchmarks/for_vs_array_each.rb

  • Committer: Package Import Robot
  • Author(s): Laurent Bigonville
  • Date: 2012-03-07 16:36:21 UTC
  • Revision ID: package-import@ubuntu.com-20120307163621-bztj2b8860dxpzs7
Tags: upstream-0.10.0
ImportĀ upstreamĀ versionĀ 0.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'rubygems'
 
2
require 'tach'
 
3
 
 
4
data = ["some", "var", "goes", "in", :here, 0]
 
5
Tach.meter(1_000_000) do
 
6
  tach('for') do
 
7
    for element in data
 
8
      element == nil
 
9
    end
 
10
  end
 
11
  tach('each') do
 
12
    data.each do |element|
 
13
      element == nil
 
14
    end
 
15
  end
 
16
end
 
17
 
 
18
# ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
 
19
 
20
# +------+----------+
 
21
# | tach | total    |
 
22
# +------+----------+
 
23
# | for  | 2.958672 |
 
24
# +------+----------+
 
25
# | each | 2.983550 |
 
26
# +------+----------+
 
27