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

📄 qtime.cpp

📁 270的linux说明
💻 CPP
字号:
/*

Copyright (c) 2008, Intel Corporation. 

All rights reserved.

 

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:


    * Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer.

    * 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.

    * Neither the name of Intel Corporation nor the names of its contributors 
may be used to endorse or promote products derived from this software without 
specific prior written permission.

 

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 OWNER 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.

*/#include "qtime.h"#include <stdio.h>#include <sys/time.h>#include <unistd.h>/* ______________________________________________________________  	typedef	______________________________________________________________ */typedef  struct _BinInt32	{	__int32 i32[2];	} BigInt32;typedef  struct _BigInt64	{	__int64 i64;	} BigInt64;typedef union _bigInt	{	BigInt32 int32val;	BigInt64 int64val;	} BigInt;/* ______________________________________________________________  CQTime______________________________________________________________ */CQTime::CQTime(){	__int64 TickPerUSec;	GetCPUTicsPerUSec(&TickPerUSec);} /* CQTime *//* ______________________________________________________________  ~CQTime______________________________________________________________ */CQTime::~CQTime(){} /* ~CQTime *//* ______________________________________________________________  CQTime::GetCPUTicsPerUSec______________________________________________________________ */void CQTime::GetCPUTicsPerUSec(__int64 *pTickPerUSec){	//printf("CQTime::GetCPUTicsPerUSec(__int64 *pTickPerUSec)\n");	/*	m_CPUTicksPerMicroSecond = 1;	__try	{		_asm		{			RDTSC		}	}	__except(1)	{		return;	}	HANDLE hProcess = GetCurrentProcess();	HANDLE hThread = GetCurrentThread();	int iPriority = GetThreadPriority(hThread);	if ( iPriority != THREAD_PRIORITY_ERROR_RETURN )	{		SetPriorityClass( hProcess, REALTIME_PRIORITY_CLASS );		SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);		Sleep(0);	}	DWORD timeStart, timeStop;	__int64 t1, t2, diff, elapsedTime;	timeStart = timeGetTime();	for ( ;; )	{		timeStop = timeGetTime();		if ( (int)(timeStop - timeStart) > 0 )		{			t1 = GetCPUTicks();			break;   		}	}	timeStart = timeStop;	for ( ;; )	{		timeStop = timeGetTime();		if ( (int)(timeStop - timeStart) > 100 )		{			t2 = GetCPUTicks();			break;   		}	}	if ( iPriority != THREAD_PRIORITY_ERROR_RETURN )	{		SetThreadPriority(hThread, iPriority);		SetPriorityClass( hProcess, NORMAL_PRIORITY_CLASS );	}	diff = t2 - t1;	elapsedTime = (__int64)(timeStop - timeStart);	m_CPUTicksPerMicroSecond = (diff) / (elapsedTime * 1000);	*pTickPerUSec = m_CPUTicksPerMicroSecond;	*/} /* CQTime::GetCPUTicsPerUSec *//* ______________________________________________________________  CQTime::GetTime______________________________________________________________ */DWORD CQTime::GetTime(){	//Larry, 9/23//	printf("bug,  implement GetTime()\n");//	return GetTickCount();	struct timeval tv;	struct timezone tz;	gettimeofday(&tv, &tz);	return tv.tv_sec*1000+tv.tv_usec; 		/*	BigInt CPUTicks;	_asm	{		RDTSC		mov CPUTicks.int32val.i32[0], eax		mov CPUTicks.int32val.i32[4], edx	}	if (m_CPUTicksPerMicroSecond >= 1000)		// > 1 GHz CPUs		return CPUTicks.int64val.i64 / m_CPUTicksPerMicroSecond;	else		// adjustment for < 1 GHz CPUs		return (CPUTicks.int64val.i64 / m_CPUTicksPerMicroSecond) * 10;  */	}DWORD CQTime::GetTimeEx(){	//printf("bug,  implement GetTimeEx()\n");	//return 0;	return GetTime();}/* ______________________________________________________________  CQTime::GetCPUTicks______________________________________________________________ */__int64 CQTime::GetCPUTicks(){	printf("bug,  implement GetCPUTicks()\n");	/*	BigInt CPUTicks;	_asm	{		RDTSC			mov CPUTicks.int32val.i32[0], eax			mov CPUTicks.int32val.i32[4], edx	}	return CPUTicks.int64val.i64;  */	return 0;}

⌨️ 快捷键说明

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