return to the main page Mastering Regular Expressions
Third Edition

Listings from page 232

Chapter 6; page 232 (download)

use Time::HiRes 'time'; # So time() gives a high-resolution value.

$StartTime = time();
"abababdedfg" =~ m/^(a|b|c|d|e|f|g)+$/;
$EndTime = time();
printf("Alternation takes %.3f seconds.\n", $EndTime - $StartTime);

$StartTime = time();
"abababdedfg" =~ m/^[a-g]+$/;
$EndTime = time();
printf("Character class takes %.3f seconds.\n", $EndTime - $StartTime);

Copyright © 2024 Jeffrey Friedl

Fetch additional Third-Edition listings and data:

Fetch listings from page(s)