File: clone.pl

package info (click to toggle)
libcatmandu-perl 1.2024-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,552 kB
  • sloc: perl: 17,037; makefile: 24; sh: 1
file content (59 lines) | stat: -rwxr-xr-x 1,093 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env perl

BEGIN {
    use strict;
    use warnings;
    use FindBin;
    use File::Spec ();
    use lib File::Spec->catdir($FindBin::Bin, '..', 'lib');
    use Catmandu ();
    use Benchmark qw(:all);
}

package NothingFix;

use strict;
use warnings;
use Moo;
use Clone qw(clone);

sub fix {
    $_[0];
}

package CloneFix;

use strict;
use warnings;
use Moo;
use Clone qw(clone);

sub fix {
    clone($_[0]);
}

package DataCloneFix;

use strict;
use warnings;
use Moo;
use Data::Clone qw(clone);

sub fix {
    clone($_[0]);
}

package main;

my $data = Catmandu->importer('JSON',
    file => File::Spec->catfile($FindBin::Bin, 'data.json'))->first;
my $nothing_fixer = Catmandu::Fix->new(fixes => [(NothingFix->new) x 1000]);
my $clone_fixer = Catmandu::Fix->new(fixes => [(CloneFix->new) x 1000]);
my $data_clone_fixer = Catmandu::Fix->new(fixes => [(DataCloneFix->new) x 1000]);

cmpthese(10000, {
        "nothing" => sub { $nothing_fixer->fix($data) },
        "Clone" => sub { $clone_fixer->fix($data) },
        "Data::Clone" => sub { $data_clone_fixer->fix($data) },
});