Unix命令对于运行K次的基准代码 [英] Unix Command For Benchmarking Code Running K times

查看:112
本文介绍了Unix命令对于运行K次的基准代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个在Unix中执行的代码:

Suppose I have a code executed in Unix this way:

$ ./mycode

我的问题是有一种方法,我可以计算我的代码
的运行时间执行K次。例如,K = 1000的值。

My question is is there a way I can time the running time of my code executed K times. The value of K = 1000 for example.

我知道Unix的time命令,但是只执行了一个实例。

I am aware of Unix "time" command, but that only executed 1 instance.

推荐答案

尝试

$ time ( your commands )

写一个循环,在括号中重复您的命令。

write a loop to go in the parens to repeat your command as needed.

好的,我们可以解决命令行太长的问题。这是bash语法,如果你使用另一个shell你可能必须使用 expr(1)

Okay, we can solve the command line too long issue. This is bash syntax, if you're using another shell you may have to use expr(1).

$ time (
> while ((n++ < 100)); do echo "n = $n"; done
> )

real    0m0.001s
user    0m0.000s
sys     0m0.000s

这篇关于Unix命令对于运行K次的基准代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆