【发布时间】:2016-05-22 16:55:47
【问题描述】:
我必须衡量 /dev/urandom 的效率作为一项任务。我有以下任务:检查,您可以在 1 分钟内从 /dev/urandom 获得多少字节的数据。不要将获取的数据写入磁盘,因为它可能会减慢一切。
我试过了
timeout 60s cat /dev/urandom | wc -c
但我收到的只是“终止”消息。
【问题讨论】:
我必须衡量 /dev/urandom 的效率作为一项任务。我有以下任务:检查,您可以在 1 分钟内从 /dev/urandom 获得多少字节的数据。不要将获取的数据写入磁盘,因为它可能会减慢一切。
我试过了
timeout 60s cat /dev/urandom | wc -c
但我收到的只是“终止”消息。
【问题讨论】:
添加--foreground 选项:
timeout --foreground 60s cat /dev/urandom | wc -c
--foreground:当不直接从 shell 提示符运行超时时,允许 COMMAND 从 TTY 读取并获取 TTY 信号;在这种模式下,COMMAND 的子节点不会超时
【讨论】:
对你的命令进行分组:
$ { timeout 60s cat /dev/urandom; } | wc -c
但 60 秒对我来说似乎偏高:
$ { timeout 1s cat /dev/urandom; } | wc -c
6160384 ### that's 6 Million bytes.
$ { timeout 10s cat /dev/urandom; } | wc -c
63143936 ### that's 63 Million bytes.
$ { timeout 10s cat /dev/urandom; } | wc -c
354844672 ### that's ~355 Million bytes.
但最后一个测量值会受到计算机在那段时间内所做的任何事情的影响。
【讨论】: