Command to get time in milliseconds

后端 未结 12 969
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 04:01

Is there a shell command in Linux to get the time in milliseconds?

12条回答
  •  不知归路
    2020-12-02 04:22

    I just wanted to add to Alper's answer what I had to do to get this stuff working:

    On Mac, you'll need brew install coreutils, so we can use gdate. Otherwise on Linux, it's just date. And this function will help you time commands without having to create temporary files or anything:

    function timeit() {
        start=`gdate +%s%N`
        bash -c $1
        end=`gdate +%s%N`
        runtime=$(((end-start)/1000000000.0))
        echo " seconds"
    }
    

    And you can use it with a string:

    timeit 'tsc --noEmit'
    

提交回复
热议问题