This tutorial is probably also available as a Jupyter notebook in the demo folder in the polymake source and on github.

Different versions of this tutorial: latest release, release 3.3, release 3.2, nightly master

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 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";
}
  • user_guide/tutorials/time.txt
  • Last modified: 2019/02/11 17:16
  • by oroehrig