user_guide:tutorials:time

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 4.1, release 4.0, release 3.6, nightly master

This is an old revision of the document!


Measure execution time

The benefit of using a standard programming language such as Perl is that one can use standard libraries for basic needs. 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);

This 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

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.1331729638.txt.gz
  • Last modified: 2014/01/03 15:45
  • (external edit)