Main Page   Class List   Class Members  

  • Main Page
  • User's Guide
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

sdk/extensions/authoring/source/VHACD/inc/vhacdTimer.h

Go to the documentation of this file.
00001 /* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)
00002  All rights reserved.
00003  
00004  
00005  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00006  
00007  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00008  
00009  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
00010  
00011  3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
00012  
00013  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00014  */
00015 #pragma once
00016 #ifndef VHACD_TIMER_H
00017 #define VHACD_TIMER_H
00018 
00019 #ifdef _WIN32
00020 #ifndef WIN32_LEAN_AND_MEAN
00021 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
00022 #endif
00023 #include <windows.h>
00024 #elif __MACH__
00025 #include <mach/clock.h>
00026 #include <mach/mach.h>
00027 #else
00028 #include <sys/time.h>
00029 #include <time.h>
00030 #endif
00031 
00032 namespace VHACD {
00033 #ifdef _WIN32
00034 class Timer {
00035 public:
00036     Timer(void)
00037     {
00038         m_start.QuadPart = 0;
00039         m_stop.QuadPart = 0;
00040         QueryPerformanceFrequency(&m_freq);
00041     };
00042     ~Timer(void){};
00043     void Tic()
00044     {
00045         QueryPerformanceCounter(&m_start);
00046     }
00047     void Toc()
00048     {
00049         QueryPerformanceCounter(&m_stop);
00050     }
00051     double GetElapsedTime() // in ms
00052     {
00053         LARGE_INTEGER delta;
00054         delta.QuadPart = m_stop.QuadPart - m_start.QuadPart;
00055         return (1000.0 * delta.QuadPart) / (double)m_freq.QuadPart;
00056     }
00057 
00058 private:
00059     LARGE_INTEGER m_start;
00060     LARGE_INTEGER m_stop;
00061     LARGE_INTEGER m_freq;
00062 };
00063 
00064 #elif __MACH__
00065 class Timer {
00066 public:
00067     Timer(void)
00068     {
00069         memset(this, 0, sizeof(Timer));
00070         host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &m_cclock);
00071     };
00072     ~Timer(void)
00073     {
00074         mach_port_deallocate(mach_task_self(), m_cclock);
00075     };
00076     void Tic()
00077     {
00078         clock_get_time(m_cclock, &m_start);
00079     }
00080     void Toc()
00081     {
00082         clock_get_time(m_cclock, &m_stop);
00083     }
00084     double GetElapsedTime() // in ms
00085     {
00086         return 1000.0 * (m_stop.tv_sec - m_start.tv_sec + (1.0E-9) * (m_stop.tv_nsec - m_start.tv_nsec));
00087     }
00088 
00089 private:
00090     clock_serv_t m_cclock;
00091     mach_timespec_t m_start;
00092     mach_timespec_t m_stop;
00093 };
00094 #else
00095 class Timer {
00096 public:
00097     Timer(void)
00098     {
00099         memset(this, 0, sizeof(Timer));
00100     };
00101     ~Timer(void){};
00102     void Tic()
00103     {
00104         clock_gettime(CLOCK_REALTIME, &m_start);
00105     }
00106     void Toc()
00107     {
00108         clock_gettime(CLOCK_REALTIME, &m_stop);
00109     }
00110     double GetElapsedTime() // in ms
00111     {
00112         return 1000.0 * (m_stop.tv_sec - m_start.tv_sec + (1.0E-9) * (m_stop.tv_nsec - m_start.tv_nsec));
00113     }
00114 
00115 private:
00116     struct timespec m_start;
00117     struct timespec m_stop;
00118 };
00119 #endif
00120 }
00121 #endif // VHACD_TIMER_H
Copyright © 2015-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com