From: Robert Klemme Date: 2003-06-18T17:32:25+09:00 Subject: Re: Multiline comments? This is a multi-part message in MIME format. ------=_NextPart_000_0022_01C3357C.650EEE40 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit I've augmented the code with two more tests and these are the results: 07:28:06 [temp]: ruby comments.rb user system total real default comment 0.047000 0.000000 0.047000 ( 0.047000) # comment 0.032000 0.000000 0.032000 ( 0.032000) EOF comment 0.093000 0.000000 0.093000 ( 0.093000) 'EOF' comment 0.094000 0.000000 0.094000 ( 0.094000) =begin comment 0.031000 0.000000 0.031000 ( 0.031000) """ comment 0.094000 0.000000 0.094000 ( 0.094000) 07:28:46 [temp]: =begin =end is the fastest for multiline comments with # style being only a bit slower. Regards robert ------=_NextPart_000_0022_01C3357C.650EEE40 Content-Type: application/octet-stream; name="comments.rb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="comments.rb" #!/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 { < 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("'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("=begin 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\"] """ } } } ------=_NextPart_000_0022_01C3357C.650EEE40--