====== Measure execution time ======
The benefit of using a standard programming language such as Perl is that one can use standard libraries for basic needs. For example, one can measure the runtime/execution time of a sequence of commands. Here is an example showing how to benchmark two different convex hull algorithms/codes on the same example.
use Benchmark qw(:all);
$r=rand_sphere(3,1000,seed=>1); $t=timeit(1,'$r->FACETS;'); print timestr($t);
$r=rand_sphere(3,1000,seed=>1); $t=timeit(1,'prefer_now("beneath_beyond");$r->FACETS;'); print timestr($t);
Note that if timing a user function, you have to provide the application your function lives in:
polytope > $t=timeit(1,'Polymake::polytope::rand_box(10,2000,1);');
The above code does not work in a [[scripting:start|script]] file (.pl) because of polymake's modifications to Perl. You rather want to use something like this.
use Benchmark qw(:all);
use application 'polytope';
my $r=rand_sphere(3,100,seed=>1);
sub getfacets{
$r->FACETS;
}
sub myBenchmark{
my $t=Benchmark::timeit(1,"getfacets");
print timestr($t);
}
or that
use Benchmark qw(:all);
use application 'polytope';
sub myBenchmark($$) {
my ($d,$n)=@_;
my $r=rand_sphere($d,$n,seed=>1);
my $t0= Benchmark->new;
$r->FACETS;
my $t1=Benchmark->new;
my $td1=timediff($t1,$t0);
print "FACETS: ".timestr($td1)."\n";
}