Leser: 1
|< 1 2 >| | 11 Einträge, 2 Seiten |
1
2
3
$string = '123456789B31S';
$string = substr($string,4,(length($string)-6));
print "$string\n";
QuoteBenchmark: timing 10000000 iterations of regexp, substr...
regexp: 16 wallclock secs (14.23 usr + 0.03 sys = 14.26 CPU) @ 701213.10/s
(n=10000000)
substr: 33 wallclock secs (30.75 usr + 0.06 sys = 30.81 CPU) @ 324622.63/s
(n=10000000)
1
2
3
4
5
6
use Benchmark;
timethese (10000000, {
'substr' => sub { my $x = '123456789B31S';
$string = substr($string,4,(length($string)-6)); },
'regexp' => sub { my $x = '123456789B31S';
$string =~ s/^.{4}(.+).{2}$/$1/; }});
QuoteBenchmark: timing 1000000 iterations of regexp, substr...
regexp: 44 wallclock secs (39.13 usr + 0.13 sys = 39.26 CPU) @ 25473.81/s (n=1000000)
substr: 4 wallclock secs ( 3.71 usr + -0.01 sys = 3.70 CPU) @ 270562.77/s (n=1000000)
1
2
3
4
5
6
use Benchmark;
timethese (1000000, {
'substr' => sub { my $string = '123456789B31S';
$string = substr($string,4,(length($string)-6)); },
'regexp' => sub { my $string = '123456789B31S';
$string =~ s/^.{4}(.+).{2}$/$1/; }});
$string = substr($string,4,-2);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#! /usr/bin/perl
use strict;
use warnings;
use Benchmark;
timethese (1000000, {
'substr' => sub { my $string = '123456789B31S';
$string = substr($string,4,(length($string)-6)); },
'tauli' => sub { my $string = '123456789B31S';
$string = substr($string,4,-2); },
'regexp' => sub { my $string = '123456789B31S';
$string =~ s/^.{4}(.+).{2}$/$1/; }});
peters@ronin:~/test> perl perl.pl
Benchmark: timing 1000000 iterations of regexp, substr, tauli...
regexp: 40 wallclock secs (40.02 usr + 0.00 sys = 40.02 CPU) @ 24987.51/s (n=1000000)
substr: 7 wallclock secs ( 7.46 usr + 0.00 sys = 7.46 CPU) @ 134048.26/s (n=1000000)
tauli: 6 wallclock secs ( 5.19 usr + 0.00 sys = 5.19 CPU) @ 192678.23/s (n=1000000)
|< 1 2 >| | 11 Einträge, 2 Seiten |