zoukankan      html  css  js  c++  java
  • 效率测试-----过期检测(毫秒级)

    测试机器处理效率,或者做效率优化的适合:

     1 #include <time.h>
     2 #include <sys/time.h>
     3 void getCurrentTime(char* buf)    
     4 {   
     5    struct timeval tv;  
     6  
     7    struct timezone tz; 
     8  
     9    struct tm         *p;
    10 
    11    gettimeofday(&tv,&tz);
    12     
    13    p = localtime(&tv.tv_sec);  
    14 
    15    sprintf(buf,"time_now:%d-%d-%d %d:%d:%d.%ld
    ", 1900+p->tm_year, 1+p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec/1000);  
    16 }  
     1 #include <sys/time.h>
     2 #include <time.h>
     3 #define  LOG_TIME
     4 用法:
     5      struct timeval t0,t1;
     6      #ifdef LOG_TIME
     7         gettimeofday(&t0,NULL);
     8      #endif
     9      #ifdef LOG_TIME
    10         gettimeofday(&t1,NULL);
    11         LOGE("function:%s,,previewSize:%dx%d,,ts_makeup_skin_cleanDt ==%ld", __FUNCTION__,jframeWidth,jframeHeight,
    12                 (1000000 * (t1.tv_sec - t0.tv_sec) + t1.tv_usec - t0.tv_usec)/1000);
    13      #endif

     过期检测Java层:

     1 int checkdate() {
     2         Date now = new Date();
     3         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//可以方便地修改日期格式
     4         String hehe = dateFormat.format( now );
     5         System.out.println(hehe);
     6         Calendar c = Calendar.getInstance();//可以对每个时间域单独修改
     7         int year = c.get(Calendar.YEAR);
     8         int month = c.get(Calendar.MONTH) + 1;
     9         Log.e(TAG, "timeout year = " + year + "  month = " + month);
    10         if (year>VALID_YEAR) {
    11                return 0;
    12         }
    13         if ((year==VALID_YEAR) && (month>VALID_MONTH)) {
    14            return 0;
    15         }
    16         return 1;
    17     }

    过期时间检测C++层:

     1 #define VALID_YEAR 2015
     2 #define VALID_MONTH 3
     3 
     4 static int checkDate()
     5 {
     6     struct timeval tv;
     7     struct tm *tm;
     8     gettimeofday(&tv, NULL);
     9     tm = localtime(&tv.tv_sec);
    10     int year   = tm->tm_year+1900;
    11     int month  = tm->tm_mon+1;
    12     if (year>VALID_YEAR) {
    13        return 0;
    14     }
    15     if ((year==VALID_YEAR) && (month>VALID_MONTH)) {
    16        return 0;
    17     }
    18     return 1;
    19 }
  • 相关阅读:
    3月工作问题总结
    【读书笔记】linux编程艺术
    项目管理工具 Trac入门
    [node.js]开放平台接口调用测试
    mysql 高并发更新计数问题
    memcache 问题 socket or its streams already null in trueClose call
    hadoop学习笔记
    node.js学习与应用
    mc参数备忘&javajson备忘
    WCF技术剖析_学习笔记之三
  • 原文地址:https://www.cnblogs.com/cy568searchx/p/3951874.html
Copyright © 2011-2022 走看看