Download vendor/libigl/include/igl/Timer.h from AVSim/simulation-package: direct link, hf CLI and curl.
- Browser
- Download file 4.25 kB
-
https://huggingface.co/datasets/AVSim/simulation-package/resolve/main/vendor/libigl/include/igl/Timer.h
- Command line
-
hf download hf://datasets/AVSim/simulation-package/vendor/libigl/include/igl/Timer.h
-
curl -L -o Timer.h https://huggingface.co/datasets/AVSim/simulation-package/resolve/main/vendor/libigl/include/igl/Timer.h
4.25 kB
| // This file is part of libigl, a simple c++ geometry processing library. | |
| // | |
| // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com> | |
| // | |
| // This Source Code Form is subject to the terms of the Mozilla Public License | |
| // v. 2.0. If a copy of the MPL was not distributed with this file, You can | |
| // obtain one at http://mozilla.org/MPL/2.0/. | |
| // High Resolution Timer. | |
| // | |
| // Resolution on Mac (clock tick) | |
| // Resolution on Linux (1 us not tested) | |
| // Resolution on Windows (clock tick not tested) | |
| namespace igl | |
| { | |
| class Timer | |
| { | |
| public: | |
| // default constructor | |
| Timer(): | |
| stopped(0), | |
| frequency(), | |
| startCount(), | |
| endCount() | |
| startCount(0), | |
| endCount(0) | |
| startCount(), | |
| endCount() | |
| { | |
| QueryPerformanceFrequency(&frequency); | |
| startCount.QuadPart = 0; | |
| endCount.QuadPart = 0; | |
| startCount = 0; | |
| endCount = 0; | |
| startCount.tv_sec = startCount.tv_usec = 0; | |
| endCount.tv_sec = endCount.tv_usec = 0; | |
| stopped = 0; | |
| } | |
| // default destructor | |
| ~Timer() | |
| { | |
| } | |
| //Raw mach_absolute_times going in, difference in seconds out | |
| double subtractTimes( uint64_t endTime, uint64_t startTime ) | |
| { | |
| uint64_t difference = endTime - startTime; | |
| static double conversion = 0.0; | |
| if( conversion == 0.0 ) | |
| { | |
| mach_timebase_info_data_t info; | |
| kern_return_t err = mach_timebase_info( &info ); | |
| //Convert the timebase into seconds | |
| if( err == 0 ) | |
| conversion = 1e-9 * (double) info.numer / (double) info.denom; | |
| } | |
| return conversion * (double) difference; | |
| } | |
| // start timer | |
| void start() | |
| { | |
| stopped = 0; // reset stop flag | |
| QueryPerformanceCounter(&startCount); | |
| startCount = mach_absolute_time(); | |
| gettimeofday(&startCount, NULL); | |
| } | |
| // stop the timer | |
| void stop() | |
| { | |
| stopped = 1; // set timer stopped flag | |
| QueryPerformanceCounter(&endCount); | |
| endCount = mach_absolute_time(); | |
| gettimeofday(&endCount, NULL); | |
| } | |
| // get elapsed time in second | |
| double getElapsedTime() | |
| { | |
| return this->getElapsedTimeInSec(); | |
| } | |
| // get elapsed time in second (same as getElapsedTime) | |
| double getElapsedTimeInSec() | |
| { | |
| return this->getElapsedTimeInMicroSec() * 0.000001; | |
| } | |
| // get elapsed time in milli-second | |
| double getElapsedTimeInMilliSec() | |
| { | |
| return this->getElapsedTimeInMicroSec() * 0.001; | |
| } | |
| // get elapsed time in micro-second | |
| double getElapsedTimeInMicroSec() | |
| { | |
| double startTimeInMicroSec = 0; | |
| double endTimeInMicroSec = 0; | |
| if(!stopped) | |
| QueryPerformanceCounter(&endCount); | |
| startTimeInMicroSec = | |
| startCount.QuadPart * (1000000.0 / frequency.QuadPart); | |
| endTimeInMicroSec = endCount.QuadPart * (1000000.0 / frequency.QuadPart); | |
| if (!stopped) | |
| endCount = mach_absolute_time(); | |
| return subtractTimes(endCount,startCount)/1e-6; | |
| if(!stopped) | |
| gettimeofday(&endCount, NULL); | |
| startTimeInMicroSec = | |
| (startCount.tv_sec * 1000000.0) + startCount.tv_usec; | |
| endTimeInMicroSec = (endCount.tv_sec * 1000000.0) + endCount.tv_usec; | |
| return endTimeInMicroSec - startTimeInMicroSec; | |
| } | |
| private: | |
| // stop flag | |
| int stopped; | |
| // ticks per second | |
| LARGE_INTEGER frequency; | |
| LARGE_INTEGER startCount; | |
| LARGE_INTEGER endCount; | |
| uint64_t startCount; | |
| uint64_t endCount; | |
| timeval startCount; | |
| timeval endCount; | |
| }; | |
| } | |