Changed timer to use CGAL::Timer.

Reduced number of benchmark cases to have acceptable runtimes.
Removed makefile to make tests run in CGAL's test suit.
This commit is contained in:
Lutz Kettner 2004-04-08 10:01:04 +00:00
parent ab108a06fc
commit 61b902ebb5
5 changed files with 32 additions and 123 deletions

View File

@ -1,32 +0,0 @@
#ifndef TIMER_HXX
#define TIMER_HXX
#include <unistd.h>
#include <sys/time.h>
struct Timer
{
public:
struct timeval t1,t2;
double t;
void start()
{
gettimeofday (&t1, NULL);
}
void stop()
{
gettimeofday (&t2, NULL);
t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) / 1000000.0;
}
void reset()
{
t = 0.0;
}
};
#endif

View File

@ -4,8 +4,7 @@
#include <CGAL/Box_intersection_d/all_pairs.h>
#include <CGAL/Box_intersection_d/one_way_scan.h>
#include "Timer.h"
#include <CGAL/Timer.h>
#include <iostream>
#include <sstream>
@ -15,6 +14,8 @@
#include <cstdio>
#include <cmath>
bool test_failed = false;
typedef CGAL::Box_intersection_d::Box_d< int, 3 > Box;
typedef CGAL::Box_intersection_d::Box_traits_d< Box > Box_adapter;
@ -120,17 +121,18 @@ test( const char* filename1, const char* filename2 )
callback2( result_tree );
std::cout << "all pairs ...... " << std::flush;
Timer timer;
CGAL::Timer timer;
timer.start();
CGAL::Box_intersection_d::all_pairs( boxes1.begin(), boxes1.end(),
boxes2.begin(), boxes2.end(),
callback1, Traits(), 2 );
timer.stop();
std::cout << "got " << callback1.counter << " intersections in "
<< timer.t << " seconds." << std::endl;
<< timer.time() << " seconds." << std::endl;
std::cout << "one way scan ...... " << std::flush;
timer.reset();
timer.start();
CGAL::Box_intersection_d::one_way_scan( boxes1.begin(), boxes1.end(),
boxes2.begin(), boxes2.end(),
@ -140,7 +142,7 @@ test( const char* filename1, const char* filename2 )
callback2, Traits(), 2 );
timer.stop();
std::cout << "got " << callback2.counter << " intersections in "
<< timer.t << " seconds." << std::endl;
<< timer.time() << " seconds." << std::endl;
callback2.counter = 0;
result_tree.clear();
@ -154,7 +156,7 @@ test( const char* filename1, const char* filename2 )
callback2, Traits(), cutoff );
timer.stop();
std::cout << "got " << callback2.counter << " intersections in "
<< timer.t << " seconds." << std::endl;
<< timer.time() << " seconds." << std::endl;
if( callback1.counter != callback2.counter ) {
unsigned int missing = countMissingItems( result_all_pairs,
@ -163,6 +165,7 @@ test( const char* filename1, const char* filename2 )
std::cout << "!! failed !! " << missing << " missing and "
<< duplicates << " duplicate intersections in tree result."
<< std::endl;
test_failed = true;
}
else
std::cout << "--- passed --- " << std::endl;
@ -178,5 +181,8 @@ int main( int argc, char ** argv ) {
file2 << "data/test" << n << "_set2.box" << std::ends;
test( file1.str().c_str(), file2.str().c_str() );
}
if ( test_failed)
return 1;
return 0;
}

View File

@ -163,7 +163,7 @@ void operator()() {
outfile << "# problemsize streamingtime scanningtime" << std::endl;
outfile.precision(9);
outfile << std::fixed;
for( unsigned int n = 8; n < 2000000; n = (int)(n * 1.3)) {
for( unsigned int n = 1024; n < 200000; n = (int)(n * 8)) {
test_n( n, outfile );
}
}
@ -204,9 +204,12 @@ int main( int argc, char ** argv ) {
test<float> c;
c();
if( failed != 0 )
std::cout << "a total number of " << failed << " tests failed!" << std::endl;
else
std::cout << "all tests passed." << std::endl;
if( failed != 0 ) {
std::cout << "a total number of " << failed << " tests failed!"
<< std::endl;
return 1;
}
std::cout << "all tests passed." << std::endl;
return 0;
}

View File

@ -1,69 +0,0 @@
# Created by the script create_makefile
# This is the makefile for compiling a CGAL application.
#---------------------------------------------------------------------#
# include platform specific settings
#---------------------------------------------------------------------#
# Choose the right include file from the <cgalroot>/make directory.
# CGAL_MAKEFILE = ENTER_YOUR_INCLUDE_MAKEFILE_HERE
include $(CGAL_MAKEFILE)
#---------------------------------------------------------------------#
# compiler flags
#---------------------------------------------------------------------#
CXXFLAGS = \
$(CGAL_CXXFLAGS) \
$(LONG_NAME_PROBLEM_CXXFLAGS) \
$(DEBUG_OPT) \
-I../../include \
-O2 \
-falign-functions=4 -fprefetch-loop-arrays -march=pentium3 \
# -fexpensive-optimizations
#---------------------------------------------------------------------#
# linker flags
#---------------------------------------------------------------------#
LIBPATH = \
$(CGAL_LIBPATH)
LDFLAGS = \
$(LONG_NAME_PROBLEM_LDFLAGS) \
$(CGAL_LDFLAGS)
#---------------------------------------------------------------------#
# target entries
#---------------------------------------------------------------------#
all: \
automated_test$(EXE_EXT) \
random_set_test$(EXE_EXT)
automated_test$(EXE_EXT): automated_test$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)automated_test automated_test$(OBJ_EXT) $(LDFLAGS)
random_set_test$(EXE_EXT): random_set_test$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)random_set_test random_set_test$(OBJ_EXT) $(LDFLAGS)
benchmark$(EXE_EXT): benchmark$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)benchmark benchmark$(OBJ_EXT) $(LDFLAGS)
clean: \
automated_test.clean \
random_set_test.clean \
benchmark.clean
depend:
$(CXX) *.C $(CXXFLAGS) -MM | grep "/KM/projects" -v > .depend
include .depend
#---------------------------------------------------------------------#
# suffix rules
#---------------------------------------------------------------------#
.C$(OBJ_EXT):
$(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) $<

View File

@ -4,8 +4,7 @@
// compare segment tree against brute force and simple implementations
#include <CGAL/Box_intersection_d/one_way_scan.h>
#include <CGAL/Box_intersection_d/all_pairs.h>
#include "Timer.h"
#include <CGAL/Timer.h>
#include <iostream>
#include <cstdlib>
@ -134,9 +133,9 @@ test_n( unsigned int n,
boxes2 = boxes1;
std::cout << std::endl;
Counter_callback callback0, callback1, callback2;
Timer timer;
CGAL::Timer timer;
if( n < 20000 ) {
if( n < 5000 ) {
std::cout << "all pairs ... " << std::flush;
timer.start();
CGAL::Box_intersection_d::all_pairs( boxes1.begin(), boxes1.end(),
@ -144,7 +143,7 @@ test_n( unsigned int n,
callback0, Traits(), DIM - 1 );
timer.stop();
std::cout << "got " << callback0.counter << " intersections in "
<< timer.t << " seconds."
<< timer.time() << " seconds."
<< std::endl;
timer.reset();
}
@ -159,7 +158,7 @@ test_n( unsigned int n,
callback1, Traits(), DIM - 1);
timer.stop();
std::cout << "got " << callback1.counter << " intersections in "
<< timer.t << " seconds."
<< timer.time() << " seconds."
<< std::endl;
std::cout << "segment tree ... " << std::flush;
@ -171,7 +170,7 @@ test_n( unsigned int n,
callback2, Traits(), cutoff, setting );
timer.stop();
std::cout << "got " << callback2.counter << " intersections in "
<< timer.t << " seconds." << std::endl;
<< timer.time() << " seconds." << std::endl;
if( callback1.counter != callback2.counter ||
n < 20000 && callback0.counter != callback1.counter )
@ -193,7 +192,7 @@ void operator()() {
std::cout << "-------------------------" << std::endl;
std::cout << "DIM = " << DIM << std::endl;
std::cout << "-------------------------" << std::endl;
for( unsigned int n = 8; n < 200000; n = (int)(n * 1.3)) {
for( unsigned int n = 1024; n < 200000; n = (int)(n * 8)) {
std::cout << "bipartite case: " << std::endl;
test_n( n, CGAL::Box_intersection_d::BIPARTITE );
//std::cout << "complete case: " << std::endl;
@ -258,10 +257,12 @@ int main( int argc, char ** argv ) {
std::cout << "-------------------------" << std::endl;
//d();
if( failed != 0 )
if( failed != 0 ) {
std::cout << "a total number of " << failed
<< " tests failed!" << std::endl;
else
std::cout << "all tests passed." << std::endl;
return 1;
}
std::cout << "all tests passed." << std::endl;
return 0;
}