代码拉取完成,页面将自动刷新
同步操作将从 计算机系统基础/malloc_lab 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
* ftimer.c - Estimate the time (in seconds) used by a function f
*
* Copyright (c) 2002, R. Bryant and D. O'Hallaron, All rights reserved.
* May not be used, modified, or copied without permission.
*
* Function timers that estimate the running time (in seconds) of a function f.
* ftimer_itimer: version that uses the interval timer
* ftimer_gettod: version that uses gettimeofday
*/
#include <stdio.h>
#include <sys/time.h>
#include "ftimer.h"
/* function prototypes */
static void init_etime(void);
static double get_etime(void);
/*
* ftimer_itimer - Use the interval timer to estimate the running time
* of f(argp). Return the average of n runs.
*/
double ftimer_itimer(ftimer_test_funct f, void *argp, int n)
{
double start, tmeas;
int i;
init_etime();
start = get_etime();
for (i = 0; i < n; i++)
f(argp);
tmeas = get_etime() - start;
return tmeas / n;
}
/*
* ftimer_gettod - Use gettimeofday to estimate the running time of
* f(argp). Return the average of n runs.
*/
double ftimer_gettod(ftimer_test_funct f, void *argp, int n)
{
int i;
struct timeval stv, etv;
double diff;
gettimeofday(&stv, NULL);
for (i = 0; i < n; i++)
f(argp);
gettimeofday(&etv,NULL);
diff = 1E3*(etv.tv_sec - stv.tv_sec) + 1E-3*(etv.tv_usec-stv.tv_usec);
diff /= n;
return (1E-3*diff);
}
/*
* Routines for manipulating the Unix interval timer
*/
/* The initial value of the interval timer */
#define MAX_ETIME 86400
/* static variables that hold the initial value of the interval timer */
static struct itimerval first_u; /* user time */
static struct itimerval first_r; /* real time */
static struct itimerval first_p; /* prof time*/
/* init the timer */
static void init_etime(void)
{
first_u.it_interval.tv_sec = 0;
first_u.it_interval.tv_usec = 0;
first_u.it_value.tv_sec = MAX_ETIME;
first_u.it_value.tv_usec = 0;
setitimer(ITIMER_VIRTUAL, &first_u, NULL);
first_r.it_interval.tv_sec = 0;
first_r.it_interval.tv_usec = 0;
first_r.it_value.tv_sec = MAX_ETIME;
first_r.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &first_r, NULL);
first_p.it_interval.tv_sec = 0;
first_p.it_interval.tv_usec = 0;
first_p.it_value.tv_sec = MAX_ETIME;
first_p.it_value.tv_usec = 0;
setitimer(ITIMER_PROF, &first_p, NULL);
}
/* return elapsed real seconds since call to init_etime */
static double get_etime(void) {
struct itimerval v_curr;
struct itimerval r_curr;
struct itimerval p_curr;
getitimer(ITIMER_VIRTUAL, &v_curr);
getitimer(ITIMER_REAL,&r_curr);
getitimer(ITIMER_PROF,&p_curr);
return (double) ((first_p.it_value.tv_sec - r_curr.it_value.tv_sec) +
(first_p.it_value.tv_usec - r_curr.it_value.tv_usec)*1e-6);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。