File: bench_integer.rb

package info (click to toggle)
jruby 1.5.1-1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze
  • size: 46,252 kB
  • ctags: 72,039
  • sloc: ruby: 398,155; java: 169,482; yacc: 3,782; xml: 2,469; ansic: 415; sh: 279; makefile: 78; tcl: 40
file content (60 lines) | stat: -rw-r--r-- 1,140 bytes parent folder | download | duplicates (5)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#######################################################################
# bench_integer.rb
#
# Benchmark suite for the Integer methods.  Deprecated methods and
# aliases are not benchmarked. To avoid using Integer methods within
# the test suite, we use for loops instead of Integer#times.
#######################################################################
require "benchmark"

MAX = 200000

Benchmark.bm(35) do |x|
   x.report("Integer#chr"){
      for i in 1..MAX
         65.chr
      end
   }

   x.report("Integer#downto"){
      for i in 1..MAX
         10.downto(1){|n| }
      end
   }

   x.report("Integer#floor"){
      for i in 1..MAX
         (-1).floor
      end
   }

   x.report("Integer#integer?"){
      for i in 1..MAX
         100.integer?
      end
   }

   x.report("Integer#next"){
      for i in 1..MAX
         100.next
      end
   }

   x.report("Integer#times"){
      for i in 1..MAX
         10.times{ |n| }
      end
   }

   x.report("Integer#to_i"){
      for i in 1..MAX
         10.to_i
      end
   }

   x.report("Integer#upto"){
      for i in 1..MAX
         0.upto(10){ |n| }
      end
   }
end