Skip to content

@schwern /gist:466256
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/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% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.