一、写在前面:这篇文章是借鉴其他两个大佬的文章,这里仅仅是搬运过来保存一下,以免之后忘记时找不到原文。
Linux平台C语言获取时间差(微秒级)原文链接:http://blog.chinaunix.net/uid-26808060-id-4101137.html
复制到vim时的格式错乱问题原文链接:https://blog.csdn.net/wzy_1988/article/details/50264285
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
int timeval_subtract(struct timeval*result, struct timeval* x, struct timeval *y);
int main(int argc, char **argv)
{
struct timeval start,stop,diff;
gettimeofday(&start,0);
printf("this is a test\n");
gettimeofday(&stop,0);
timeval_subtract(&diff,&start,&stop);
printf("总计用时:%d 微秒\n",diff.tv_usec);
}
/**
* 计算两个时间的间隔,得到时间差
* @param struct timeval* resule 返回计算出来的时间
* @param struct timeval* x 需要计算的前一个时间
* @param struct timeval* y 需要计算的后一个时间
* return -1 failure ,0 success
**/
int timeval_subtract(struct timeval* result, struct timeval* x, struct timeval* y)
{
int nsec;
if ( x->tv_sec>y->tv_sec )
return -1;
if ( (x->tv_sec==y->tv_sec) && (x->tv_usec>y->tv_usec) )
return -1;
result->tv_sec = ( y->tv_sec-x->tv_sec );
result->tv_usec = ( y->tv_usec-x->tv_usec );
if (result->tv_usec<0)
{
result->tv_sec--;
result->tv_usec+=1000000;
}
return 0;
}
复制到vim中时,会出现格式错乱的情况,如
此时只需要设置vim为paste模式即可。复制完之后记得退出paste模式。
设置命令为:
:set paste //进入paste模式
:set nopaste //退出paste模式
paste模式主要帮我们做了一下事情
- textwidth设置为0
- wrapmargin设置为0
- set noai
- set nosi
- softtabstop设置为0
- revins重置
- ruler重置
- showmatch重置
- formatoptions使用空值