File: benchmark_args.pl

package info (click to toggle)
libposix-strftime-compiler-perl 0.46-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 156 kB
  • sloc: perl: 439; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 730 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use Benchmark qw/:all/;
use POSIX qw//;
use POSIX::strftime::Compiler;

my $fmt = $ARGV[0] || '%d/%b/%Y:%T';

my $t = time;
my @lt = localtime($t);

my $psc = POSIX::strftime::Compiler->new($fmt);
print "sample: " . $psc->to_string(@lt) ."\n";

cmpthese(timethese(-1, {
    'compiler' => sub {
        $psc->to_string(@lt);
    },
    'compiler_function' => sub {
        POSIX::strftime::Compiler::strftime($fmt, @lt);
    },
    'posix_and_locale' => sub {
        my $old_locale = POSIX::setlocale(&POSIX::LC_ALL);
        POSIX::setlocale(&POSIX::LC_ALL, 'C');
        POSIX::strftime($fmt,@lt);
        POSIX::setlocale(&POSIX::LC_ALL, $old_locale);
    },
    'posix' => sub {
        POSIX::strftime($fmt,@lt);
    },
}));