File Coverage

blib/lib/Surveyor/Benchmark/SchwartzianTransform/SortFilesBySize.pm
Criterion Covered Total %
statement 35 42 83.3
branch n/a
condition n/a
subroutine 9 12 75.0
pod 3 3 100.0
total 47 57 82.4


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