Wrap text
Theme:
Clean (Pastie)
All Hallow's Eve
Blackboard
Brilliance Black
Cobalt
Espresso Libre
IDLE
Mac Classic
MagicWB (Amiga)
Pastels on Dark
Slate
Slush and Poppies
Sunburst
Sunburst (Josh)
Twilight
Vibrant Ink
benchmark
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
require 'benchmark'
total = (ENV ['TOTAL' ] || 1_000 ).to_i
strings = Dir ["spec/**/*_spec.rb" ]
numbers = Array .new (strings.size ).fill { |i | strings[i].size }
Benchmark .bmbm do |x |
x.report ("Fixnum#<=>" ) do
times = 0
while times < total
size = numbers.size
i = j = 0
while i < size
while j < size
numbers[i] <=> numbers[j]
j += 1
end
i += 1
end
times += 1
end
end
x.report ("String#<=>" ) do
times = 0
while times < total
size = numbers.size
i = j = 0
while i < size
while j < size
strings[i] <=> strings[j]
j += 1
end
i += 1
end
times += 1
end
end
end
before
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
angelo:rubinius brian$ ruby - v
ruby 1.8 .6 (2007 - 09 - 24 patchlevel 111 ) [universal- darwin9.0 ]
angelo:rubinius brian$ TOTAL = 1_000 ruby spaceship.rb
Rehearsal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Fixnum
String
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - total: 4. 380000sec
user system total real
Fixnum
String
angelo:rubinius brian$ shotgun/ rubinius - v
rubinius 0.8 .0 (ruby 1.8 .6 compatible) (681156e0b) (02 / 05 / 2008 ) [i686- apple- darwin9.1.0 ]
angelo:rubinius brian$ TOTAL = 1_000 shotgun/ rubinius spaceship.rb
Rehearsal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Fixnum
String
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - total: 13. 349197sec
user system total real
Fixnum
String
after while replaced Integer#times
1
2
3
4
5
6
7
8
9
10
angelo:rubinius brian$ TOTAL = 1_000 shotgun/ rubinius spaceship.rb
Rehearsal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Fixnum
String
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - total: 6. 414071sec
user system total real
Fixnum
String
after ByteArray#compare_bytes fixed to take lengths
1
2
3
4
5
6
7
8
9
10
angelo:rubinius brian$ rm spaceship.rbc ; TOTAL = 1_000 shotgun/ rubinius spaceship.rb
Rehearsal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Fixnum
String
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - total: 3. 031205sec
user system total real
Fixnum
String