Geom Software - C++ Programming and Geometry Libraries
Fade3D Documentation pages v0.9
Example1 - Fade2D Benchmark

This example measures the performance of Fade2D on your computer. Additionally it demonstrates how to use the integrated postscript writer.


Output


Note
  • Make sure you link against the fast release version and not the debug binary.
  • Points in degenerate position may slow down the computations.
  • The time consumption is linear (otherwise your machine has not enough memory)


main()

Inserts 1, 10, 20, 50, 100 million random points

#include <Fade_2D.h>
#include <stdio.h>
#include <map>
#include <string>
#include <sstream>
#include <iomanip>
using namespace GEOM_FADE2D;
void diagram(std::map<unsigned,double>& mNumTime);
int main()
{
std::map<unsigned,double> mMillPointsSeconds;
mMillPointsSeconds[1];
mMillPointsSeconds[10];
mMillPointsSeconds[20];
mMillPointsSeconds[50]; // mem consumption: 10.5 GB
// mMillPointsSeconds[100]; // mem consumption: 21 GB, deactivated as a precaution
// Benchmark loop
for(std::map<unsigned,double>::iterator it(mMillPointsSeconds.begin());
it!=mMillPointsSeconds.end();++it)
{
// Generate random points
std::vector<Point2> vInputPoints;
unsigned millionPoints(it->first);
for(unsigned i=0;i<1000000*millionPoints;++i)
{
double x=-100+(200.0*rand()/(RAND_MAX+1.0));
double y=-100+(200.0*rand()/(RAND_MAX+1.0));
vInputPoints.push_back(Point2(x,y));
}
// Start timer
timer("Insert Points");
// Triangulate
Fade_2D dt(millionPoints*1000000);
dt.enableMultithreading(); // Under Linux multithreading can be enabled
dt.insert(vInputPoints);
// Stop timer
double elapsed=timer("Insert Points");
mMillPointsSeconds[millionPoints]=elapsed;
}
// Draw a diagram
diagram(mMillPointsSeconds);
return 0;
}

Visualization

The diagram(..) function takes the elapsed time and uses the postscript writer of the library to draw a diagram.

void diagram(std::map<unsigned,double>& mMillionTime)
{
if(mMillionTime.empty()) return;
Visualizer2 vis("example1.ps");
// Draw coordinate axes.
Color cBlue(0,0,1,0.1);
Color cBlack(0,0,0,0.01);
vis.addObject(Segment2(Point2(0,0),Point2(100,0)),cBlue);
vis.addObject(Segment2(Point2(0,0),Point2(0,60)),cBlue);
vis.addObject(Label(Point2(45,-5),"million points",false),cBlack);
vis.addObject(Label(Point2(-5,55),"t[s]",false),cBlack);
vis.addObject(Label(Point2(40,55),"Fade2D on your machine",false),cBlack);
Color cRed(1,0,0,0.1);
Point2 lastPoint(0,0);
for(std::map<unsigned,double>::iterator it(mMillionTime.begin());it!=mMillionTime.end();++it)
{
unsigned millionPoints(it->first);
double seconds(it->second);
double xPosition=millionPoints*100.0/mMillionTime.rbegin()->first;
double yPosition=seconds*50.0/mMillionTime.rbegin()->second;
Point2 currentPoint(xPosition,yPosition);
vis.addObject(Segment2(lastPoint,currentPoint),cRed);
vis.addObject(Label(currentPoint,""),cBlue);
vis.addObject(Label(Point2(xPosition-2,-2)," "+convertToString(millionPoints),false),cBlack);
vis.addObject(Label(Point2(xPosition,0),""),cBlack);
vis.addObject(Label(Point2(-6,yPosition)," "+convertToString(seconds)+" s",false),cBlack);
vis.addObject(Label(Point2(0,yPosition),""),cBlack);
vis.addObject(Label(currentPoint,""),cBlue);
lastPoint=currentPoint;
}
vis.writeFile();
}