Posted to tcl by kostix at Tue Dec 25 00:29:53 GMT 2007view raw
- #! /usr/bin/perl
-
- use strict;
- use warnings;
- use Time::HiRes qw( gettimeofday tv_interval );
-
- my $s = "A string with { spaces";
-
- my ($t1, $t2, @parts);
-
- $t1 = [gettimeofday];
-
- for my $i (1..1000) {
- @parts = split('\S+', $s);
- }
-
- $t2 = tv_interval($t1) * 1e6 / 1000;
-
- print "$t2 usec\n";
-
- ---
- RESULTS:
-
- C:\tmp\benchmark>perl split.pl
- 8.902 usec
-
- C:\tmp\benchmark>perl split.pl
- 8.905 usec
-
- C:\tmp\benchmark>perl split.pl
- 8.883 usec
-
- ---
- Tcl:
-
- (bin) 16 % time { set parts [split [regsub -all {\s+} $s { }] { }] } 1000
- 13.007 microseconds per iteration
- (bin) 17 % time { set parts [split [regsub -all {\s+} $s { }] { }] } 1000
- 13.119 microseconds per iteration
- (bin) 18 % time { set parts [split [regsub -all {\s+} $s { }] { }] } 1000
- 13.01 microseconds per iteration
-