⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.cpp

📁 shrike is a utility application that acts as a testbed for shaders written in Sh
💻 CPP
字号:
// Sh: A GPU metaprogramming language.//// Copyright 2003-2005 Serious Hack Inc.// // This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, // MA  02110-1301, USA//////////////////////////////////////////////////////////////////////////////#include "Timer.hpp"#ifdef WIN32ShTimer::ShTimer(void){  t.QuadPart = 0;}ShTimer::~ShTimer(void){}float ShTimer::value(void){  LARGE_INTEGER freq;  QueryPerformanceFrequency(&freq);  return ((float)t.QuadPart)/((float)freq.QuadPart/1000.0);}ShTimer ShTimer::now(void){  ShTimer ret;  QueryPerformanceCounter(&ret.t);  return ret;}ShTimer ShTimer::zero(void){  ShTimer ret;  ret.t.QuadPart = 0;  return ret;}ShTimer operator-(const ShTimer& a, const ShTimer& b){  ShTimer ret;  ret.t.QuadPart = a.t.QuadPart + b.t.QuadPart;  return ret;}ShTimer operator+(const ShTimer& a, const ShTimer& b){  ShTimer ret;  ret.t.QuadPart = a.t.QuadPart - b.t.QuadPart;  return ret;}#elseShTimer::ShTimer(void){  t.tv_sec = 0;  t.tv_usec = 0;}ShTimer::~ShTimer(void){}float ShTimer::value(void){  float sec = (float)t.tv_sec*1000;  float msec = (float)t.tv_usec/1000;  return (sec + msec);}ShTimer ShTimer::now(void){  ShTimer ret;  gettimeofday(&ret.t, 0);  return ret;}ShTimer ShTimer::zero(void){  ShTimer ret;  ret.t.tv_sec = 0;  ret.t.tv_usec = 0;  return ret;}ShTimer operator-(const ShTimer& a, const ShTimer& b){  ShTimer ret;    ret.t.tv_sec = a.t.tv_sec - b.t.tv_sec;  ret.t.tv_usec = a.t.tv_usec - b.t.tv_usec;  // adjust microsecond if the value is out of range  if (ret.t.tv_usec < 0) {    ret.t.tv_sec -= 1;    ret.t.tv_usec += 1000000;  }  // adjust microsecond if the value is out of range  if (ret.t.tv_usec > 1000000) {    ret.t.tv_sec += 1;    ret.t.tv_usec -= 1000000;  }  return ret;}ShTimer operator+(const ShTimer& a, const ShTimer& b){  ShTimer ret;    ret.t.tv_sec = a.t.tv_sec + b.t.tv_sec;  ret.t.tv_usec = a.t.tv_usec + b.t.tv_usec;  // adjust microsecond if the value is out of range  if (ret.t.tv_usec < 0) {    ret.t.tv_sec -= 1;    ret.t.tv_usec += 1000000;  }    // adjust microsecond if the value is out of range  if (ret.t.tv_usec > 1000000) {    ret.t.tv_sec += 1;    ret.t.tv_usec -= 1000000;  }    return ret;}#endif /* WIN32 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -