您的位置:首页 > 其它

获得函数执行的次数

2007-04-29 00:42 246 查看
//GetFuncCallTimes.h

#ifndef _GETFUNCCALLTIMES_H
#define _GETFUNCCALLTIMES_H

#include <map>
#include <string>

class CGetFuncCallTimes
{
public:
std::map<std::string, long> call_count;

void Increase(std::string s)
{
++call_count[s];
}

long Count(std::string s)
{
return call_count[s];
}
};

extern CGetFuncCallTimes fct;

#endif

//GetFuncCallTimes.cpp

#include "GetFuncCallTimes.h"

CGetFuncCallTimes fct;

使用方法如下:

在源文件中包含该头文件: #include "GetFuncCallTimes.h"

在需要统计的函数里面加上一行: fct.Increase("function1");

输出时: long lTimes = fct.Count("function1");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: