易截截图软件、单文件、免安装、纯绿色、仅160KB

Linux获取毫秒级时间


Linux获取毫秒级时间
Moakap
在软件设计中经常会用到关于时间的处理,用来计算语句、函数的执行时间,这时就需要精确到毫秒甚至是微妙的时间。
 
int gettimeofday(struct
timeval *tv, struct timezone *tz);
int settimeofday(const
struct timeval *tv , const struct timezone *tz);
 
struct timeval {
   
time_t      tv_sec;     /* seconds */
   
suseconds_t tv_usec;    /*
microseconds */
};
 
struct timezone {
   
int tz_minuteswest;     /* minutes
west of Greenwich
*/
    int
tz_dsttime;         /* type of DST
correction */
};
 
下面是个简单的例子,用来统计程序的执行时间:
       …
struct timeval
t_start,t_end;
   
long cost_time = 0;
 
//get start
time
gettimeofday(&t_start,
NULL);
printf("Start
time: %ld us", t_start.tv_usec);
 
//some
operation

 
//get end time
gettimeofday(&t_end,
NULL);
printf("End
time: %ld us", t_end.tv_usec);
 
//calculate
time slot
cost_time =
t_end.tv_usec - t_start.tv_usec;
printf("Cost
time: %ld us", cost_time);

 
输出:
Start time:
438061 us
End time:
459867 us
Cost time:
21806 us


相关文档:

linux install 命令

install
1.作用
install命令的作用是安装或升级软件或备份数据,它的使用权限是所有用户。
2.格式
(1)install [选项]... 来源 目的地
(2)install [选项]... 来源... 目录
(3)install -d [选项]... 目录...
在前两种格式中,会将<来源>复制至<目的地>或将多个<来源>文件复制至已存在的< ......

UNIX/linux系统下FTP自动上传文件脚本

方法一: Expect 实现交互
UNIX 窗口中 输入以下命令:
expect ftplinux.txt 10.0.15.22 ftplinux.txt
ftplinux.txt 中内容如下:
--开始-----
spawn ftp [lindex $argv 0]
expect "Name(*):"
send "ftp\r"
expect "Password:*"
send "hell05a\r"
expect "ftp> ......

linux压缩和解压缩命令大全


linux压缩和解压缩命令大全

        .tar
  解包:tar zxvf FileName.tar
  打包:tar czvf FileName.tar DirName
  ---------------------------------------------
  .gz
  解压1:gunzip FileName.gz
  解压2:gzip -d FileName.gz
  压缩:gzip File ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号