#!/usr/bin/perl use strict; use warnings; use Benchmark qw( cmpthese ); cmpthese -2, { by_substr => sub { my $nomedir = '20070502-11'; my $anno = substr $nomedir, 0, 4; my $mese = substr $nomedir, 4, 2; my $giorno = substr $nomedir, 6, 2; my $progressivo = substr $nomedir, 9, 2; }, by_unpack => sub { my $nomedir = '20070502-11'; my ($anno, $mese, $giorno, $progressivo) = unpack 'A4 A2 A2 x A2', $nomedir; }, }; poletti@PolettiX:~/sviluppo/perl$ /opt/perl-5.8.8/bin/perl numstat.pl Rate by_unpack by_substr by_unpack 417553/s -- -32% by_substr 613303/s 47% -- poletti@PolettiX:~/sviluppo/perl$ /opt/perl-5.10.0/bin/perl numstat.pl Rate by_unpack by_substr by_unpack 372754/s -- -34% by_substr 565358/s 52% -- poletti@PolettiX:~/sviluppo/perl$ /opt/perl-5.8.8/bin/perl numstat.pl Rate by_unpack by_substr by_unpack 415531/s -- -33% by_substr 616325/s 48% -- poletti@PolettiX:~/sviluppo/perl$ /opt/perl-5.10.0/bin/perl numstat.pl Rate by_unpack by_substr by_unpack 374480/s -- -33% by_substr 562716/s 50% -- poletti@PolettiX:~/sviluppo/perl$ /opt/perl-5.8.8/bin/perl numstat.pl Rate by_unpack by_substr by_unpack 415531/s -- -33% by_substr 616325/s 48% -- poletti@PolettiX:~/sviluppo/perl$ /opt/perl-5.10.0/bin/perl numstat.pl Rate by_unpack by_substr by_unpack 369821/s -- -34% by_substr 562716/s 52% --