File Coverage

blib/lib/Surveyor/Benchmark/SchwartzianTransform/SortFilesBySize.pm
Criterion Covered Total %
statement 37 44 84.0
branch n/a
condition n/a
subroutine 10 13 76.9
pod 3 3 100.0
total 50 60 83.3


line stmt bran cond sub pod time code
1 2     2   2760 use 5.014;
  2         8  
2              
3             package Surveyor::Benchmark::SchwartzianTransform::SortFilesBySize;
4 2     2   12 use strict;
  2         10  
  2         57  
5              
6 2     2   12 use warnings;
  2         4  
  2         61  
7 2     2   11 no warnings;
  2         7  
  2         811  
8              
9             our $VERSION = '0.122';
10              
11             =encoding utf8
12              
13             =head1 NAME
14              
15             Surveyor::Benchmark::SchwartzianTransform::SortFilesBySize - Compare the low-tech and Schwartzian Transform sorts
16              
17             =head1 SYNOPSIS
18              
19             Use with C from L:
20              
21             % survey -p Surveyor::Benchmark::SchwartzianTransform::SortFilesBySize '/glob/pattern/*'
22              
23             =head1 DESCRIPTION
24              
25             =over 4
26              
27             =item set_up
28              
29             =cut
30              
31             sub set_up {
32 1     1 1 534 my( $self, @args ) = @_;
33              
34 1         3 my $glob = $args[0];
35 1         279 @L::files = glob $glob;
36 1         17 print "Testing with " . @L::files . " files\n";
37              
38 1         5 my $transform = q|map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, -M ]|;
39 1         2 my $sort = q|sort { -M $a <=> -M $b }|;
40              
41             my $code = {
42 0     0   0 assign => sub { my @r = @L::files },
43 1     1   747 'glob' => sub { my @files = glob $glob },
44              
45 1     1   3412 sort_names => sub { sort { $a cmp $b } @L::files },
  57         103  
46 1     1   343 sort_names_assign => sub { my @r = sort { $a cmp $b } @L::files },
  57         104  
47 1     1   134 sort_times_assign => eval "sub { my \@r = $sort \@L::files }",
  1         631  
  65         1221  
  0         0  
  0         0  
  1         3110  
  65         1192  
  0         0  
  0         0  
  1         3735  
  65         135  
  1         828  
  65         131  
48              
49             ordinary_orig => eval "sub { my \@r = $sort glob \$glob }",
50             ordinary_mod => eval "sub { my \@r = $sort \@L::files }",
51              
52             schwartz_orig => eval "sub { $transform, glob \$glob }",
53             schwartz_orig_assign => eval "sub { my \@r = $transform, glob \$glob }",
54             schwartz_mod => eval "sub { my \@r = $transform, \@L::files }",
55             };
56              
57 1         7 foreach my $key ( keys %$code ) {
58 2     2   16 no strict 'refs';
  2         6  
  2         283  
59 10         22 *{"bench_$key"} = $code->{$key};
  10         42  
60             }
61             }
62              
63             =item tear_down
64              
65             =cut
66              
67 0     0 1   sub tear_down { 1; }
68              
69             =item test
70              
71             =cut
72              
73             sub test {
74 0     0 1   warn "I haven't defined tests yet";
75             }
76              
77             =back
78              
79             =head1 TO DO
80              
81              
82             =head1 SEE ALSO
83              
84              
85             =head1 SOURCE AVAILABILITY
86              
87             This source is in a Git repository:
88              
89             https://github.com/briandfoy/surveyor-benchmark-schwartziantransform-sortfilesbysize
90              
91             =head1 AUTHOR
92              
93             brian d foy, C<< >>
94              
95             =head1 COPYRIGHT AND LICENSE
96              
97             Copyright © 2013-2021, brian d foy . All rights reserved.
98              
99             You may redistribute this under the terms as Artistic License 2.0.
100              
101             =cut
102              
103             1;