📄 timer.c
字号:
/* * Copyright (c) 1996 W. Richard Stevens. All rights reserved. * Permission to use or modify this software and its documentation only for * educational purposes and without fee is hereby granted, provided that * the above copyright notice appear in all copies. The author makes no * representations about the suitability of this software for any purpose. * It is provided "as is" without express or implied warranty. */#include "cliserv.h"#include <sys/time.h>void tvsub(struct timeval *, struct timeval *);struct timeval tvstart, tvend;voidstart_timer(){ if (gettimeofday(&tvstart, NULL) < 0) err_sys("start_timer: gettimeofday error");}doubleprint_timer(){ double triptime; if (gettimeofday(&tvend, NULL) < 0) err_sys("print_timer: gettimeofday error"); tvsub(&tvend, &tvstart); triptime = ((double) tvend.tv_sec) * 1000.0 + ((double) tvend.tv_usec) / 1000.0; /* in millisec */ printf("rtt = %9.3f ms\n", triptime); return(triptime);}/* Subtract two timeval structures: *end -= *start */voidtvsub(struct timeval *end, struct timeval *start){ if ((end->tv_usec -= start->tv_usec) < 0) { --end->tv_sec; end->tv_usec += 1000000; } end->tv_sec -= start->tv_sec;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -