Which seems to be bang on. If you introduce '$' into the characters that are used to create the random strings, there is a slight difference:Benchmark: timing 25 iterations of Double, Single... Double: 2 wallclock secs ( 1.57 usr + 0.01 sys = 1.58 CPU) @ 15 +.82/s (n=25) Single: 1 wallclock secs ( 1.57 usr + 0.01 sys = 1.58 CPU) @ 15 +.82/s (n=25) Rate Double Single Double 15.8/s -- -0% Single 15.8/s 0% --
So it would seem that using single or double quotes, apart from functional differences, is merely style. I prefer to use double quotes almost always, except for short single-letter strings, but that's the influence of C where single quotes can only be used for single characters, and double quotes meant 'string'.Benchmark: timing 25 iterations of Double, Single... Double: 3 wallclock secs ( 3.13 usr + 0.14 sys = 3.27 CPU) @ 7 +.65/s (n=25) Single: 3 wallclock secs ( 3.18 usr + 0.06 sys = 3.24 CPU) @ 7 +.72/s (n=25) Rate Double Single Double 7.65/s -- -1% Single 7.72/s 1% --
#!/usr/bin/perl use Benchmark qw [ cmpthese ]; my (@letter) = ('A'..'Z','a'..'z','0'..'9'); my (@single,@double); sub RandomCrap { return join ('', map { $letter[rand(@letter)] } 0..64); } sub Prep { for (my $i = 0; $i < 5; $i++) { my $func = '@x = ('; for (my $n = 0; $n < 1000; $n++) { $func .= "'".RandomCrap()."',"; } $func .= ')'; push (@single, $func); } @double = map { tr/'/"/; $_ } @single; } sub Evalu { my ($array) = @_; foreach my $func (@$array) { eval $func; } } Prep(); cmpthese (25, { 'Single' => sub { Evalu (\@single); }, 'Double' => sub { Evalu (\@double); }, } );
In reply to Re: String Delimiters
by tadman
in thread String Delimiters
by pegasus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |