Here is a little benchmark for comments that were discussed here,
$ ruby1.7 comments.rb
user system total real
default comment 0.140000 0.000000 0.140000 ( 0.141877)
comment 0.140000 0.000000 0.140000 ( 0.133724)
EOF comment 0.500000 0.020000 0.520000 ( 0.633371)
""" comment 0.520000 0.010000 0.530000 ( 0.579245)
I know that times i’m repeating code are too big for default case we use
comments in, but if it will be used i.e. in a function executed from
1…999999.each i guess runtime will be the same.
P.S. Maybe i’m totally wrong and it’s not even worth speaking about it 
That’s my code (i’m sure it sucks, but anyway):
#!/usr/bin/ruby
require "benchmark"
include Benchmark
bm(15) { |x|
x.report(“default comment”) {
100000.times {
=begin
#------------------------------------------------------------ Array#slice
arr.slice( anInteger ) -> anObject
arr.slice( start, length ) -> aSubArray
arr.slice( aRange ) -> aSubArray
···
#------------------------------------------------------------------------
Synonym for Array#[ ].
a = [ “a”, “b”, “c”, “d”, “e” ]
a.slice(2) + a.slice(0) + a.slice(1) #=> “cab”
a.slice(6) #=> nil
a.slice(1, 2) #=> [“b”, “c”]
a.slice(1…3) #=> [“b”, “c”, “d”]
a.slice(4…7) #=> [“e”]
a.slice(6…10) #=> nil
a.slice(-3, 3) #=> [“c”, “d”, “e”]
=end
}
}
x.report("# comment") {
100000.times {
#------------------------------------------------------------ Array#slice
arr.slice( anInteger ) -> anObject
arr.slice( start, length ) -> aSubArray
arr.slice( aRange ) -> aSubArray
#------------------------------------------------------------------------
Synonym for Array#[ ].
a = [ “a”, “b”, “c”, “d”, “e” ]
a.slice(2) + a.slice(0) + a.slice(1) #=> “cab”
a.slice(6) #=> nil
a.slice(1, 2) #=> [“b”, “c”]
a.slice(1…3) #=> [“b”, “c”, “d”]
a.slice(4…7) #=> [“e”]
a.slice(6…10) #=> nil
a.slice(-3, 3) #=> [“c”, “d”, “e”]
}
}
x.report(“EOF comment”) {
100000.times {
<<EOF
------------------------------------------------------------ Array#slice
arr.slice( anInteger ) -> anObject
arr.slice( start, length ) -> aSubArray
arr.slice( aRange ) -> aSubArray
Synonym for Array#[ ].
a = [ “a”, “b”, “c”, “d”, “e” ]
a.slice(2) + a.slice(0) + a.slice(1) #=> “cab"
a.slice(6) #=> nil
a.slice(1, 2) #=> [“b”, “c”]
a.slice(1…3) #=> [“b”, “c”, “d”]
a.slice(4…7) #=> [“e”]
a.slice(6…10) #=> nil
a.slice(-3, 3) #=> [“c”, “d”, “e”]
EOF
}
}
x.report(”""" comment") {
100000.times {
"""
#------------------------------------------------------------ Array#slice
arr.slice( anInteger ) -> anObject
arr.slice( start, length ) -> aSubArray
arr.slice( aRange ) -> aSubArray
#------------------------------------------------------------------------
Synonym for Array#[ ].
a = [ “a”, “b”, “c”, “d”, “e” ]
a.slice(2) + a.slice(0) + a.slice(1) #=> “cab”
a.slice(6) #=> nil
a.slice(1, 2) #=> [“b”, “c”]
a.slice(1…3) #=> [“b”, “c”, “d”]
a.slice(4…7) #=> [“e”]
a.slice(6…10) #=> nil
a.slice(-3, 3) #=> [“c”, “d”, “e”]
"""
}
}
}
–
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.