File: bench.pl

package info (click to toggle)
liburl-encode-xs-perl 0.03-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 352 kB
  • sloc: perl: 1,612; makefile: 3
file content (71 lines) | stat: -rwxr-xr-x 1,626 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl

use strict;
use warnings;

use Benchmark       qw[];
use URL::Encode::XS qw[];
use URL::Encode::PP qw[];
use List::Util      qw[shuffle];

{
    my $s = join '', shuffle 'A'..'F', map { sprintf "%%%.2X", $_ } 0x20..0x29;
    print "Benchmarking url_decode() PP vs XS:\n\n";

    Benchmark::cmpthese( -10, {
        'XS' => sub {
            my $v = URL::Encode::XS::url_decode($s);
        },
        'PP' => sub {
            my $v = URL::Encode::PP::url_decode($s);
        },
    });
}

{
    my $s = join '', shuffle 'A'..'F', map { chr } 0x20..0x29;

    print "\nBenchmarking url_encode() PP vs XS:\n\n";

    Benchmark::cmpthese( -10, {
        'XS' => sub {
            my $v = URL::Encode::XS::url_encode($s);
        },
        'PP' => sub {
            my $v = URL::Encode::PP::url_encode($s);
        },
    });
}

{
    my $s = join '&', map { "$_=%41+%42" } 'A'..'Z', 'A'..'F';

    print "\nBenchmarking url_params_mixed() PP vs XS:\n\n";

    Benchmark::cmpthese( -10, {
        'XS' => sub {
            my $v = URL::Encode::XS::url_params_mixed($s);
        },
        'PP' => sub {
            my $v = URL::Encode::PP::url_params_mixed($s);
        },
    });
}

eval {
    require CGI::Deurl::XS;

    my $s = join '&', map { "$_=%41+%42" } 'A'..'Z', 'A'..'F';

    print "\nBenchmarking URL::Encode::XS vs CGI::Deurl::XS\n\n";

    Benchmark::cmpthese( -10, {
        'URL::Encode::XS' => sub {
            my $hash = URL::Encode::XS::url_params_mixed($s);
        },
        'CGI::Deurl::XS' => sub {
            my $hash = CGI::Deurl::XS::parse_query_string($s);
        },
    });
};