English 中文(简体)
以毫秒级精度获取微基准标记脚本的时间
原标题:Retrieving time for microbenchmarking scripts with millisecond-level accuracy
  • 时间:2012-05-24 15:33:33
  •  标签:
  • shell
  • time

我要用 shell 脚本读取一个文件, 并在此计算读取文件所需的时间。 我创建的方法低于方法, 可以在文件读取的开始和结束以毫秒获得时间, 我会计算时间差, 但是它不会添加 小时+ 分钟+ 秒, 并显示需要的数值输入 。

方法方法方法

  getCurrentTimeInMili()
   {
    hourTime=$(($(date +%H)*3600))
    minuteTime=$(($(date +%m)*60))
    secondTime=$(date +%S)
    timeInMili= $(($hourTime + $minuteTime + $secondTime));
    return timeInMili
   }

Error ./testshell.sh: line 17: return: timeInMili: numeric argument required

最佳回答

多次引用 date 表示他们的返回值可能有些不同步 -- -- 如果我们在第二个边界之前再次引用, 这可能很糟糕。 最好只拨打日期一次, 并检索所有想要的信息, 比如 :

getCurrentTimeInMili() {
  date + %H 3600 * %M 60 * + %S + 1000 * %N 1000000 / + p  | dc
}

startTime=$(getCurrentTimeInMili)
sleep 5
endTime=$(getCurrentTimeInMili)

如果您不需要如此精度, 请使用 < code> time < /code> 内嵌, 如 :

time sleep 5
问题回答

省略 timeInMili/code> 和 $ 之间的间距

timeInMili= $(($hourTime + $minuteTime + $secondTime));
           ^
          This to

timeInMili=$(($hourTime + $minuteTime + $secondTime));




相关问题
KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

unix find command

how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......