Geom Software - C++ Programming and Geometry Libraries

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 <stdio.h>
#include <map>
#include <string>
#include <sstream>
#include <iomanip>
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
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);
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);