#ifndef SYSSTDTIME_H_
#define SYSSTDTIME_H_
#include "time.h"
#include <string>
#include <unistd.h>
#include <sys/time.h>
class time_statstic{
private:
typedef struct timeval timeer_t ;
public:
explicit time_statstic( const std::string & str , void* (*func)( void * ,char* ) ) ;
~time_statstic() ;
private:
std::string m_str ;
timeer_t start ;
timeer_t end ;
void*( *m_func)(void* ,char *) ;
};
#endif /* SYSSTDTIME_H_ */
#include "SYSstdTime.h"
time_statstic::time_statstic( const std::string & str,void* (*func)( void * ,char*) ):m_str(str)\
,m_func(func){
gettimeofday(&start ,NULL ) ;
}
time_statstic::~time_statstic()
{
gettimeofday(&end ,NULL ) ;
long d=(end.tv_sec-start.tv_sec)*1000000+( end.tv_usec - start.tv_usec) ;
(*m_func)( &d , (char*)m_str.c_str() ) ;
}