-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
port to c++11 #89
port to c++11 #89
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
include_directories(..) | ||
|
||
add_executable(trivial trivial.cpp) | ||
target_link_libraries(trivial ${LIB_NAME} ${EXTRA_LIBS} ${Boost_LIBRARIES}) | ||
target_link_libraries(trivial ${LIB_NAME} ${EXTRA_LIBS}) | ||
|
||
add_executable(usage usage.cpp) | ||
target_link_libraries(usage ${LIB_NAME} ${EXTRA_LIBS} ${Boost_LIBRARIES}) | ||
target_link_libraries(usage ${LIB_NAME} ${EXTRA_LIBS}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,12 +37,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
#include <iostream> | ||
#include <fstream> | ||
|
||
#ifdef BOOST_STDINT | ||
#include <boost/cstdint.hpp> | ||
using boost::uint64_t; | ||
#else // BOOST_STDINT | ||
#include <stdint.h> | ||
#endif // BOOST_STDINT | ||
#include <cstdint> | ||
using std::uint64_t; | ||
|
||
using namespace std; | ||
using namespace Nabo; | ||
|
@@ -129,55 +125,20 @@ typename NearestNeighbourSearch<T>::Matrix createQuery(const typename NearestNei | |
return q; | ||
} | ||
|
||
#ifdef __MACH__ | ||
#include <mach/clock.h> | ||
#include <mach/mach.h> | ||
#else | ||
#include <time.h> | ||
#endif | ||
|
||
#ifdef _POSIX_TIMERS | ||
namespace boost | ||
#include <chrono> | ||
using std::chrono::high_resolution_clock; | ||
using std::chrono::duration_cast; | ||
struct timer | ||
{ | ||
/* | ||
High-precision timer class, using gettimeofday(). | ||
The interface is a subset of the one boost::timer provides, | ||
but the implementation is much more precise | ||
on systems where clock() has low precision, such as glibc. | ||
*/ | ||
struct timer | ||
{ | ||
typedef uint64_t Time; | ||
|
||
timer():_start_time(curTime()){ } | ||
void restart() { _start_time = curTime(); } | ||
double elapsed() const // return elapsed time in seconds | ||
{ return double(curTime() - _start_time) / double(1000000000); } | ||
|
||
private: | ||
Time curTime() const { | ||
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time | ||
clock_serv_t cclock; | ||
mach_timespec_t ts; | ||
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); | ||
clock_get_time(cclock, &ts); | ||
mach_port_deallocate(mach_task_self(), cclock); | ||
#else | ||
struct timespec ts; | ||
#ifdef CLOCK_PROCESS_CPUTIME_ID | ||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts); | ||
#else // BSD and old Linux | ||
clock_gettime(CLOCK_PROF, &ts); | ||
#endif | ||
#endif | ||
return Time(ts.tv_sec) * Time(1000000000) + Time(ts.tv_nsec); | ||
} | ||
Time _start_time; | ||
}; | ||
} | ||
#else // _POSIX_TIMERS | ||
#include <boost/timer.hpp> | ||
#endif // _POSIX_TIMERS | ||
timer():_start_time(high_resolution_clock::now()){ } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd make |
||
void restart() { _start_time = high_resolution_clock::now(); } | ||
double elapsed() const // return elapsed time in seconds | ||
{ return duration_cast<chrono::nanoseconds>(high_resolution_clock::now() - _start_time).count() / double(1000000000); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be possible to write this more concise as return duration_cast<duration<double>>(high_resolution_clock::now() - _start_time).count(); |
||
|
||
private: | ||
high_resolution_clock::time_point _start_time; | ||
}; | ||
|
||
#endif // __NABE_TEST_HELPERS_H | ||
|
||
/* vim: set ts=8 sw=8 tw=0 noexpandtab cindent softtabstop=8 :*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather use explicit scoping or function level
using
below.