public
Created

  • Download Gist
gistfile1.txt
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
#!/usr/bin/perl
 
use strict;
use warnings;
 
use File::Copy;
use Benchmark qw(cmpthese);
 
my $file = shift;
my $moved = "$file.mv";
 
cmpthese shift || -3, {
mv => sub {
system "mv" => $file => $moved;
die if $?;
system "mv" => $moved => $file;
die if $?;
},
move => sub {
move $file, $moved or die $!;
move $moved, $file or die $!;
},
rename => sub {
rename $file, $moved or die $!;
rename $moved, $file or die $!;
},
cp => sub {
system "cp" => $file => $moved;
die if $?;
system "cp" => $moved => $file;
die if $?;
},
copy => sub {
copy $file, $moved or die $!;
copy $moved, $file or die $!;
},
};
 
__END__
 
For a small file (3 lines of text)
Rate cp mv copy move rename
cp 68.1/s -- -2% -95% -99% -99%
mv 69.6/s 2% -- -95% -99% -99%
copy 1282/s 1782% 1741% -- -74% -82%
move 5000/s 7240% 7080% 290% -- -30%
rename 7143/s 10386% 10157% 457% 43% --
 
 
For a large file (2.4 megs /usr/share/dict/words)
Rate cp mv copy move rename
cp 36.0/s -- -48% -49% -99% -99%
mv 69.6/s 93% -- -1% -99% -99%
copy 70.6/s 96% 1% -- -99% -99%
move 5000/s 13780% 7080% 6980% -- -30%
rename 7143/s 19729% 10157% 10014% 43% --

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.