【问题标题】:Bash, how to get the average execution time of multiple average execution times?Bash,如何获得多个平均执行时间的平均执行时间?
【发布时间】:2023-03-07 17:46:01
【问题描述】:

对于一个项目,我需要确定哪种编程语言执行速度最快,所以我有一大堆 hello world。我需要获得 1000 次迭代的平均值,然后我需要这 1000 次中的 100 次的平均值。我对 bash 的了解相当有限。我已经阅读了 time 命令和 for 循环,但我不知道如何获取命令的结果并将其相加。

非常感谢您提供任何帮助,并在此先感谢您。

【问题讨论】:

    标签: bash time execution


    【解决方案1】:

    time for i in {1..1000}; do something; done

    { time for i in {1..1000}; do perl -e 'print "foo";' >/dev/null 2>&1; done ; } 2>perl

    { time for i in {1..1000}; do ruby -e 'print "foo"' >/dev/null 2>&1; done ; } 2>ruby

    为您的语言做到这一点,然后做数学运算

    cat perl | grep real | awk '{print $2}' 会告诉你时间。

    然后根据这些计算平均值。

    如果不为你做你的工作,我不能走得太远

    【讨论】:

      猜你喜欢
      • 2011-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多