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

📄 profiler.cpp

📁 一个很好的vc底层代码
💻 CPP
字号:
/********************************************************************** * $Id: Profiler.cpp,v 1.4 2004/12/03 22:52:56 strk Exp $ * * GEOS - Geometry Engine Open Source * http://geos.refractions.net * * Copyright (C) 2001-2002 Vivid Solutions Inc. * * This is free software; you can redistribute and/or modify it under * the terms of the GNU Lesser General Public Licence as published * by the Free Software Foundation.  * See the COPYING file for more information. * **********************************************************************/#include <geos/profiler.h>namespace geos {static Profiler *internal_profiler = new Profiler();Profile::Profile(string newname){	name = newname;	totaltime = 0;	min = max = avg = 0;}Profile::~Profile(){}voidProfile::start(){	gettimeofday(&starttime, NULL);}voidProfile::stop(){	gettimeofday(&stoptime, NULL);	double elapsed = 1000000*(stoptime.tv_sec-starttime.tv_sec)+		(stoptime.tv_usec-starttime.tv_usec);	timings.push_back(elapsed);	totaltime += elapsed;	if ( timings.size() == 1 ) max = min = elapsed;	else	{		if ( elapsed > max ) max = elapsed;		if ( elapsed < min ) min = elapsed;	}	avg = totaltime / timings.size();}doubleProfile::getMax() const{	return max;}doubleProfile::getMin() const{	return min;}doubleProfile::getAvg() const{	return avg;}doubleProfile::getTot() const{	return totaltime;}unsigned intProfile::getNumTimings() const{	return timings.size();}Profiler::Profiler(){}Profiler::~Profiler(){	map<string, Profile *>::const_iterator it;	for ( it=profs.begin(); it != profs.end(); ++it )	{		delete it->second;	}}voidProfiler::start(string name){	Profile *prof;	map<string, Profile *>::iterator iter = profs.find(name);	if ( iter == profs.end() ) {		prof = new Profile(name);		profs.insert(pair<string, Profile *>(name, prof));	} else {		prof = iter->second;	}	prof->start();}voidProfiler::stop(string name){	map<string, Profile *>::iterator iter = profs.find(name);	if ( iter == profs.end() )		cerr<<name<<": no such Profile started";	iter->second->stop();}Profile *Profiler::get(string name){	Profile *prof;	map<string, Profile *>::iterator iter = profs.find(name);	if ( iter == profs.end() ) {		prof = new Profile(name);		profs.insert(pair<string, Profile *>(name, prof));	} else {		prof = iter->second;	}	return prof;}Profiler *Profiler::instance(){	return internal_profiler;}ostream&operator<< (ostream &os, const Profile &prof){	os << " num:"<<prof.getNumTimings()<<" min:"<<		prof.getMin()<<" max:"<<prof.getMax()<<		" avg:"<<prof.getAvg()<<" tot:"<<prof.getTot()<<		" ["<<prof.name<<"]";	return os;}ostream&operator<< (ostream &os, const Profiler &prof){	map<string, Profile *>::const_iterator it;	for ( it=prof.profs.begin(); it != prof.profs.end(); ++it )	{		os<<*(it->second)<<endl;	}	return os;}} // namespace geos/********************************************************************** * $Log: Profiler.cpp,v $ * Revision 1.4  2004/12/03 22:52:56  strk * enforced const return of CoordinateSequence::toVector() method to derivate classes. * * Revision 1.3  2004/11/08 12:15:35  strk * Added number of gathered timings in output. * * Revision 1.2  2004/11/08 11:19:39  strk * Profiler::get() always return a Profile (new if not existant). * * Revision 1.1  2004/11/01 16:43:04  strk * Added Profiler code. * Temporarly patched a bug in DoubleBits (must check drawbacks). * Various cleanups and speedups. * **********************************************************************/

⌨️ 快捷键说明

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