Created
July 7, 2010 03:15
-
-
Save schwern/466256 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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