mirror of
https://github.com/vgough/encfs.git
synced 2024-11-25 09:23:13 +01:00
benchmark.pl: Skip ecryptfs if mount.ecryptfs is not available
Allows the benchmark to work on OS X or when ecryptfs is not installed. Also, introduce stopwatch_start/stop helpers to cut down copy-paste code.
This commit is contained in:
parent
3643924ba3
commit
517c7bc948
@ -5,6 +5,7 @@
|
||||
use Time::HiRes qw( time );
|
||||
use File::Temp;
|
||||
use warnings;
|
||||
use feature 'state';
|
||||
|
||||
require("tests/common.pl");
|
||||
|
||||
@ -53,6 +54,12 @@ sub mount_encfs {
|
||||
}
|
||||
|
||||
sub mount_ecryptfs {
|
||||
|
||||
if(system("which mount.ecryptfs > /dev/null") != 0) {
|
||||
print "skipping ecryptfs\n";
|
||||
return "";
|
||||
}
|
||||
|
||||
my $workingDir = shift;
|
||||
|
||||
my $c = "$workingDir/ecryptfs_ciphertext";
|
||||
@ -76,54 +83,70 @@ sub ms {
|
||||
return $milliseconds;
|
||||
}
|
||||
|
||||
# stopwatch_start($name)
|
||||
# start the stopwatch for test "$name"
|
||||
sub stopwatch_start {
|
||||
stopwatch(1, shift);
|
||||
}
|
||||
|
||||
# stopwatch_stop(\@results)
|
||||
# stop the stopwatch, save time into @results
|
||||
sub stopwatch_stop {
|
||||
stopwatch(0, shift);
|
||||
}
|
||||
|
||||
sub stopwatch {
|
||||
state $start_time;
|
||||
state $name;
|
||||
my $start = shift;
|
||||
|
||||
if($start) {
|
||||
$name = shift;
|
||||
print("# $name... ");
|
||||
$start_time = time();
|
||||
} else {
|
||||
my $delta = ms(time() - $start_time);
|
||||
print("$delta ms\n");
|
||||
my $results = shift;
|
||||
push( $results, [ $name, $delta, 'ms' ] );
|
||||
}
|
||||
}
|
||||
|
||||
sub benchmark {
|
||||
my $dir = shift;
|
||||
my $start;
|
||||
our $linuxgz;
|
||||
my $delta;
|
||||
my $line;
|
||||
|
||||
my @results = ();
|
||||
|
||||
system("sync");
|
||||
print("# stream_write... ");
|
||||
$start = time();
|
||||
stopwatch_start("stream_write");
|
||||
writeZeroes( "$dir/zero", 1024 * 1024 * 100 );
|
||||
system("sync");
|
||||
$delta = time() - $start;
|
||||
push( @results, [ 'stream_write', int( 100 / $delta ), "MiB/s" ] );
|
||||
printf("done\n");
|
||||
stopwatch_stop(\@results);
|
||||
unlink("$dir/zero");
|
||||
|
||||
system("sync");
|
||||
system("cat $linuxgz > /dev/null");
|
||||
print("# extract... ");
|
||||
$start = time();
|
||||
stopwatch_start("extract");
|
||||
system("tar xzf $linuxgz -C $dir");
|
||||
system("sync");
|
||||
$delta = ms( time() - $start );
|
||||
push( @results, [ 'extract', $delta, "ms" ] );
|
||||
print("done\n");
|
||||
stopwatch_stop(\@results);
|
||||
|
||||
$du = qx(du -sm $dir | cut -f1);
|
||||
push( @results, [ 'du', $du, 'MB' ] );
|
||||
printf( "# disk space used: %d MB\n", $du );
|
||||
push( @results, [ 'du', $du, 'MiB' ] );
|
||||
printf( "# disk space used: %d MiB\n", $du );
|
||||
|
||||
system("echo 3 > /proc/sys/vm/drop_caches");
|
||||
$start = time();
|
||||
stopwatch_start("rsync");
|
||||
system("rsync -an $dir /tmp");
|
||||
$delta = time() - $start;
|
||||
push( @results, [ 'rsync', ms($delta), 'ms' ] );
|
||||
printf( "# rsync took %d ms\n", ms($delta) );
|
||||
stopwatch_stop(\@results);
|
||||
|
||||
system("echo 3 > /proc/sys/vm/drop_caches");
|
||||
system("sync");
|
||||
$start = time();
|
||||
stopwatch_start("rm");
|
||||
system("rm -Rf $dir/*");
|
||||
system("sync");
|
||||
$delta = time() - $start;
|
||||
push( @results, [ 'delete', ms($delta), 'ms' ] );
|
||||
printf( "# delete took %d ms\n", ms($delta) );
|
||||
stopwatch_stop(\@results);
|
||||
|
||||
return \@results;
|
||||
}
|
||||
@ -134,7 +157,10 @@ sub tabulate {
|
||||
$r = shift;
|
||||
my @encfs = @{$r};
|
||||
$r = shift;
|
||||
my @ecryptfs = @{$r};
|
||||
my @ecryptfs;
|
||||
if($r) {
|
||||
@ecryptfs = @{$r};
|
||||
}
|
||||
|
||||
print " Test | EncFS | eCryptfs | EncFS advantage\n";
|
||||
print ":---------------|-------------:|-------------:|---------------:\n";
|
||||
@ -144,12 +170,17 @@ sub tabulate {
|
||||
my $unit = $encfs[$i][2];
|
||||
|
||||
my $en = $encfs[$i][1];
|
||||
my $ec = $ecryptfs[$i][1];
|
||||
my $ec = 0;
|
||||
my $ratio = 0;
|
||||
|
||||
my $ratio = $ec / $en;
|
||||
if( @ecryptfs ) {
|
||||
$ec = $ecryptfs[$i][1];
|
||||
$ratio = $ec / $en;
|
||||
if ( $unit =~ m!/s! ) {
|
||||
$ratio = $en / $ec;
|
||||
}
|
||||
}
|
||||
|
||||
printf( "%-15s | %6d %-5s | %6d %-5s | %2.2f\n",
|
||||
$test, $en, $unit, $ec, $unit, $ratio );
|
||||
}
|
||||
@ -180,7 +211,10 @@ sub main {
|
||||
|
||||
print "# mounting ecryptfs\n";
|
||||
$mountpoint = mount_ecryptfs($workingDir);
|
||||
my $ecryptfs_results = benchmark($mountpoint);
|
||||
my $ecryptfs_results;
|
||||
if($mountpoint) {
|
||||
$ecryptfs_results = benchmark($mountpoint);
|
||||
}
|
||||
|
||||
cleanup($workingDir);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user