Posted to tcl by kostix at Tue Dec 25 00:29:53 GMT 2007view raw

  1. #! /usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Time::HiRes qw( gettimeofday tv_interval );
  6.  
  7. my $s = "A string with { spaces";
  8.  
  9. my ($t1, $t2, @parts);
  10.  
  11. $t1 = [gettimeofday];
  12.  
  13. for my $i (1..1000) {
  14. @parts = split('\S+', $s);
  15. }
  16.  
  17. $t2 = tv_interval($t1) * 1e6 / 1000;
  18.  
  19. print "$t2 usec\n";
  20.  
  21. ---
  22. RESULTS:
  23.  
  24. C:\tmp\benchmark>perl split.pl
  25. 8.902 usec
  26.  
  27. C:\tmp\benchmark>perl split.pl
  28. 8.905 usec
  29.  
  30. C:\tmp\benchmark>perl split.pl
  31. 8.883 usec
  32.  
  33. ---
  34. Tcl:
  35.  
  36. (bin) 16 % time { set parts [split [regsub -all {\s+} $s { }] { }] } 1000
  37. 13.007 microseconds per iteration
  38. (bin) 17 % time { set parts [split [regsub -all {\s+} $s { }] { }] } 1000
  39. 13.119 microseconds per iteration
  40. (bin) 18 % time { set parts [split [regsub -all {\s+} $s { }] { }] } 1000
  41. 13.01 microseconds per iteration
  42.