XML technologies / Regular expressions / Perl / Efficiency in Perl / Benchmarks

(Excerpt from "Regular expressions" by Jeffrey E. F. Friedl)

Anyone concerned about program efficiency will test it. In Perl, you can use the supplied module Benchmark , which is well documented (“perldoc Benchmark”). Mostly out of habit, I often write benchmark programs from scratch, using module

use Time::HiRes 'time';

and wrapping the code to be tested in the following fragment.

my $start = time;
   ...
my $delta = time - $start;
printf "Laufzeit: %.1f sec\n", $delta;

In benchmark programs, code must run long enough to produce meaningful results. Isolate the code under test from irrelevant work, or you will measure something other than what matters. For more on benchmarking problems, see The art of writing regular expressions (see Benchmarking). Benchmarking requires some adjustment in thinking, but ultimately pays off.

  

 

 

 

German edition copyright © 2008 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for private use.
Otherwise, this chapter from "Reguläre Ausdrücke" is subject to the same terms as the bound edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, storage and processing in electronic systems.

O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln

back to top