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

📄 timer.c

📁 CFL是Unix下的通用抽象库,以简化Unix下的系统软件开发,CFL库中包含几个分组的函数和宏
💻 C
字号:
/* ----------------------------------------------------------------------------   CFL - A C Foundation Library   Copyright (C) 1994-2003  Mark A Lindner   This file is part of CFL.      This library is free software; you can redistribute it and/or   modify it under the terms of the GNU Library General Public   License as published by the Free Software Foundation; either   version 2 of the License, or (at your option) any later version.      This library is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   Library General Public License for more details.      You should have received a copy of the GNU Library General Public   License along with this library; if not, write to the Free   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   ----------------------------------------------------------------------------   $Log: timer.c,v $   Revision 1.2  2003/05/07 04:46:52  markl   Added elapsed time calculations   Revision 1.1  2003/03/03 08:20:08  markl   Initial checkin (clean compile on Solaris & OS X)   ----------------------------------------------------------------------------*//* Feature test switches */#include "config.h"/* System headers *//* Local headers */#include "cfl/defs.h"#include "cfl/system.h"#include "cfl/util.h"/* Functions */c_timer_t *C_timer_create(void)  {  c_timer_t *timer = C_new(c_timer_t);  time(&(timer->created)); /* set creation time on timer */  timer->running = FALSE;    return(timer);  }/* */void C_timer_destroy(c_timer_t *timer)  {  C_free(timer);  }/* */void C_timer_start(c_timer_t *timer)  {  if(! timer->running)    {      timer->usr_time = timer->sys_time = timer->real_time = 0;    times(&(timer->t1));    gettimeofday(&(timer->tv1), NULL);    timer->running = TRUE;    }  }/* */void C_timer_resume(c_timer_t *timer)  {  if(! timer->running)    {    times(&(timer->t1));    gettimeofday(&(timer->tv1), NULL);        timer->running = TRUE;    }  }/* */void C_timer_stop(c_timer_t *timer)  {  if(timer->running)    {    times(&(timer->t2));    gettimeofday(&(timer->tv2), NULL);    timer->usr = (timer->t2.tms_utime - timer->t1.tms_utime);    timer->sys = (timer->t2.tms_stime - timer->t1.tms_stime);    timer->real = ((timer->tv2.tv_sec * 1000 + timer->tv2.tv_usec)                   - (timer->tv1.tv_sec * 1000 + timer->tv1.tv_usec));        timer->usr_time += ((float)(timer->usr) / (float)CLK_TCK);    timer->sys_time += ((float)(timer->sys) / (float)CLK_TCK);    timer->real_time += timer->real;    timer->running = FALSE;    }  }/* */void C_timer_reset(c_timer_t *timer)  {  timer->running = FALSE;  timer->usr_time = timer->sys_time = timer->real_time = 0;  }/* end of source file */

⌨️ 快捷键说明

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