Commit 261603c8 authored by incardon's avatar incardon
Browse files

Added timer.hpp

parent 4e602e28
......@@ -4,6 +4,7 @@
#include "map_grid.hpp"
#include "Point_test.hpp"
#include "Space/Shape/HyperCube.hpp"
#include "timer.hpp"
#define GS_SIZE 128
......@@ -73,9 +74,8 @@ template<typename g> void test_layout_grid3d(g & c3, size_t sz)
typedef Point_test<float> P;
timespec ts_start;
// clock_gettime(CLOCK_MONOTONIC, &ts); // Works on FreeBSD
clock_gettime(CLOCK_REALTIME, &ts_start); // Works on Linux
timer t;
t.start();
grid_key_dx<3> kk;
......@@ -112,11 +112,9 @@ template<typename g> void test_layout_grid3d(g & c3, size_t sz)
}
#ifdef VERBOSE_TEST
timespec end_time;
clock_gettime(CLOCK_REALTIME, &end_time); // Works on Linux
float time_dif =(float)( end_time.tv_sec - ts_start.tv_sec + (double)(end_time.tv_nsec - ts_start.tv_nsec)/1000000000.0 );
t.stop();
std::cout << "End : " << sz*sz*sz*16*4 << " Byte " << " Bandwidth: " << sz*sz*sz*16*4/1024/1024/time_dif << " MB/s ";
std::cout << "End : " << sz*sz*sz*16*4 << " Byte " << " Bandwidth: " << sz*sz*sz*16*4/1024/1024/t.getwct() << " MB/s ";
#endif
/////////////////////////////////// MEM CHECK ////////////////////////////////////////////////////////
......@@ -191,9 +189,8 @@ template<unsigned int dim, typename g> void test_layout_gridObjNd(g & c3, size_t
#ifdef VERBOSE_TEST
std::cout << dim << "D Array with grid_key (without redundant dimension): " << "\n";
timespec ts_start;
// clock_gettime(CLOCK_MONOTONIC, &ts); // Works on FreeBSD
clock_gettime(CLOCK_REALTIME, &ts_start); // Works on Linux
timer t;
t.start();
#endif
typedef Point_test<float> P;
......@@ -231,11 +228,9 @@ template<unsigned int dim, typename g> void test_layout_gridObjNd(g & c3, size_t
#ifdef VERBOSE_TEST
timespec end_time;
clock_gettime(CLOCK_REALTIME, &end_time); // Works on Linux
float time_dif =(float)( end_time.tv_sec - ts_start.tv_sec + (double)(end_time.tv_nsec - ts_start.tv_nsec)/1000000000.0 );
t.stop();
std::cout << "End : " << pow(sz,dim)*16*4/1024/1024 << " MB " << " Bandwidth: " << pow(sz,dim)*16*4/1024/1024/time_dif << " MB/s " << "\n";
std::cout << "End : " << pow(sz,dim)*16*4/1024/1024 << " MB " << " Bandwidth: " << pow(sz,dim)*16*4/1024/1024/t.getect() << " MB/s " << "\n";
#endif
/////////////////////////////////// MEM CHECK ////////////////////////////////////////////////////////
......@@ -307,9 +302,8 @@ template<unsigned int dim, typename g> void test_layout_gridNd(g & c3, size_t sz
#ifdef VERBOSE_TEST
std::cout << dim << "D Array with grid_key (without redundant dimension): " << "\n";
timespec ts_start;
// clock_gettime(CLOCK_MONOTONIC, &ts); // Works on FreeBSD
clock_gettime(CLOCK_REALTIME, &ts_start); // Works on Linux
timer t;
t.start();
#endif
typedef Point_test<float> P;
......@@ -345,11 +339,9 @@ template<unsigned int dim, typename g> void test_layout_gridNd(g & c3, size_t sz
#ifdef VERBOSE_TEST
timespec end_time;
clock_gettime(CLOCK_REALTIME, &end_time); // Works on Linux
float time_dif =(float)( end_time.tv_sec - ts_start.tv_sec + (double)(end_time.tv_nsec - ts_start.tv_nsec)/1000000000.0 );
t.stop();
std::cout << "End : " << pow(sz,dim)*16*4/1024/1024 << " MB " << " Bandwidth: " << pow(sz,dim)*16*4/1024/1024/time_dif << " MB/s " << "\n";
std::cout << "End : " << pow(sz,dim)*16*4/1024/1024 << " MB " << " Bandwidth: " << pow(sz,dim)*16*4/1024/1024/t.getwct() << " MB/s " << "\n";
#endif
/////////////////////////////////// MEM CHECK ////////////////////////////////////////////////////////
......@@ -603,7 +595,8 @@ BOOST_AUTO_TEST_CASE( C_array_test )
int gs = GS_SIZE;
#ifdef VERBOSE_TEST
clock_t begin_time = clock();
timer t;
t.start();
#endif
for (int i = 0 ; i < GS_SIZE ; i++)
......@@ -635,11 +628,9 @@ BOOST_AUTO_TEST_CASE( C_array_test )
}
#ifdef VERBOSE_TEST
t.stop();
clock_t end_time = clock ();
float time_dif =(float)( end_time - begin_time ) / (float) CLOCKS_PER_SEC;
std::cout << "End : " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024 << " MB " << " Bandwidth: " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024/time_dif << " MB/s \n";
std::cout << "End : " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024 << " MB " << " Bandwidth: " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024/t.getcputime() << " MB/s \n";
#endif
}
......
......@@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE( Hyper_cube_use)
// Fill the expected vector
comb<1> c[] = {{1},{-1}};
comb<1> c[] = {{{1}},{{-1}}};
// Check the linearization
check_lin(v_c1_0);
......
//
// Timer.h
//
//
#ifndef TIMER_HPP
#define TIMER_HPP
#include <time.h>
#include <sys/time.h>
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif
/*! \brief Class for cpu time benchmarking
*
* Usage:
*
* timet t;
* t.start();
*
* ... Do something
*
* t.stop();
* t.getwct();
*
*/
class timer
{
struct timespec tsstart;
clock_t cstart;
struct timespec tsstop;
clock_t cstop;
public:
timer()
{
}
void start()
{
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
tsstart.tv_sec = mts.tv_sec;
tsstart.tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_REALTIME, &tsstart);
#endif
cstart = clock();
}
void stop()
{
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
tsstop.tv_sec = mts.tv_sec;
tsstop.tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_REALTIME, &tsstop);
#endif
cstop = clock();
}
double getwct()
{
return ((double)(tsstop.tv_sec - tsstart.tv_sec)) + ((1e-9) * ((double)(tsstop.tv_nsec - tsstart.tv_nsec)));
}
double getcputime()
{
return (((double)(cstop - cstart)) / CLOCKS_PER_SEC);
}
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment