日期:2014-05-16  浏览次数:20636 次

Linux 测试程序运行的时间
Linux测试程序运行的时间一般用:
gettimeofday()

#include<android/log.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <linux/input.h>
#include <sys/ioctl.h>
#include <poll.h>
#include <netdb.h>
#include <termios.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <time.h>
#include <sys/time.h>


#define LOG_TAG "test"
#define LOGI(fmt, args...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, fmt, ##args) 
#define LOGD(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##args) 
#define LOGE(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, fmt, ##args)

struct timeval tstart,tend;
float timeuse;


int main(int argc, char **argv)
{
    gettimeofday(&tstart,NULL);
    //测试的程序。。
    gettimeofday(&tend,NULL);
   
    timeuse=1000000*(tend.tv_sec-tstart.tv_sec)+(tend.tv_usec-tstart.tv_usec);
    timeuse/=1000000;
   
    LOGI("timeuse,value:%f\n",timeuse);
   
    return 0;
}