3 个版本 (重大更改)
0.3.0 | 2024年3月5日 |
---|---|
0.2.0 | 2022年11月20日 |
0.1.1 | 2022年11月10日 |
#72 在 性能分析
每月下载量 69
390KB
2K SLoC
mntime 命令
此 mntime
命令内部使用 BSD Time time -l
或 GNU Time gtime --v
来计算平均值。
time --l
选项和 gtime --v
选项测量内存使用和执行时间。如果您只想测量执行时间,可以使用 shell 内置的 time
。
项目名称来自 m 命令和 n 次,以及来自 mean。此外,它来自 multiple number time。
因此,mntime
执行指定的 m 命令 n 次,并计算平均值。
演示
主要功能
- 测量命令时间和内存使用。
- 多次运行以计算平均值、标准差等。
动机
对于项目
- 想多次运行并计算平均值。
- 想测量程序的内存使用。
对于个人
- 学习 Rust 语言。
- 学习如何创建 TUI 工具。
- 学习如何使用 git 和 GitHub
是的,我是一个新的 Rustacean,一个通常使用 C++、C# 作为语言并使用 Perforce 进行版本控制的职业程序员。
安装
Rust 版本
MSRV: mntime
需要 rustc 1.74.0 或更高版本。
依赖工具
BSD Time 和 GNU Time。例如,在 Mac 上
# BSD Time is default installed in /usr/bin/time
# GNU Time is installed as gtime with
brew install gnu-time
如果这些选项都不可用,请使用bash内置的time命令,它只测量时间,而不测量与内存相关的数据。
mntime
cargo install mntime
还有其他方便的包可用。
使用方法
请使用-h
(简称)或--help
(全称)选项获取更多信息。
基本基准测试
mntime sleep 1
结果
Benchmark #1> sleep '1'
LEGEND : Mean ± σ (Coefficient of variation %) [Min ≦ Median ≦ Max] / Valid count
Elapsed (wall clock) time : 1 sec ± 0 ns (0.0 %) [1 sec ≦ 1 sec ≦ 1 sec] / 10
User time : 0 ns ± 0 ns (0.0 %) [0 ns ≦ 0 ns ≦ 0 ns] / 10
System time : 0 ns ± 0 ns (0.0 %) [0 ns ≦ 0 ns ≦ 0 ns] / 10
Maximum resident set size : 1.359 MiB ± 0 byte (0.0 %) [1.359 MiB ≦ 1.359 MiB ≦ 1.359 MiB] / 10
Reclaiming a frame page faults: 166 ± 0 (0.0 %) [166 ≦ 166 ≦ 166] / 10
Involuntary context switches : 3.1 ± 0.3 (9.7 %) [3 ≦ 3 ≦ 4] / 10
└─Excluding Outlier : 3 ± 0 (0.0 %) [3 ≦ 3 ≦ 3] / 9(-1)
Page size : 16,384 ± 0 (0.0 %) [16,384 ≦ 16,384 ≦ 16,384] / 5
Instructions retired : 3,106,667 ± 761.8 (0.0 %) [3,105,195 ≦ 3,107,013 ≦ 3,107,265] / 5
Cycles elapsed : 1,108,346 ± 39,878 (3.6 %) [1,075,217 ≦ 1,081,719 ≦ 1,177,488] / 5
Peak memory footprint : 903.1 KiB ± 7.869 KiB (0.9 %) [896.6 KiB ≦ 896.6 KiB ≦ 912.7 KiB] / 5
如果没有指定运行次数,它将运行10次。如果您想更改运行次数,可以使用-r
/--runs
选项。
mntime --runs 4 sleep 1
结果
Benchmark #1> sleep '1'
LEGEND : Mean ± σ (Coefficient of variation %) [Min ≦ Median ≦ Max] / Valid count
Elapsed (wall clock) time : 1 sec ± 0 ns (0.0 %) [1 sec ≦ 1 sec ≦ 1 sec] / 4
User time : 0 ns ± 0 ns (0.0 %) [0 ns ≦ 0 ns ≦ 0 ns] / 4
System time : 0 ns ± 0 ns (0.0 %) [0 ns ≦ 0 ns ≦ 0 ns] / 4
Maximum resident set size : 1.359 MiB ± 0 byte (0.0 %) [1.359 MiB ≦ 1.359 MiB ≦ 1.359 MiB] / 4
Reclaiming a frame page faults: 166 ± 0 (0.0 %) [166 ≦ 166 ≦ 166] / 4
Involuntary context switches : 3.25 ± 0.433 (13.3 %) [3 ≦ 3 ≦ 4] / 4
Page size : 16,384 ± 0 (0.0 %) [16,384 ≦ 16,384 ≦ 16,384] / 2
Instructions retired : 3,101,767 ± 30.5 (0.0 %) [3,101,737 ≦ 3,101,798 ≦ 3,101,798] / 2
Cycles elapsed : 1,127,008 ± 14,435 (1.3 %) [1,112,573 ≦ 1,141,444 ≦ 1,141,444] / 2
Peak memory footprint : 896.6 KiB ± 0 byte (0.0 %) [896.6 KiB ≦ 896.6 KiB ≦ 896.6 KiB] / 2
比较基准测试
以这种方式指定多个命令时,每个命令将执行n次,然后计算平均值。
mntime sleep 1 -- sleep 0.9 -- sleep 1.1
或者
mntime 'sleep 1' 'sleep 0.9' 'sleep 1.1'
结果展开在这里
Benchmark #1> sleep '1'
LEGEND : Mean ± σ (Coefficient of variation %) [Min ≦ Median ≦ Max] / Valid count
Elapsed (wall clock) time : 1 sec ± 0 ns (0.0 %) [1 sec ≦ 1 sec ≦ 1 sec] / 10
User time : 0 ns ± 0 ns (0.0 %) [0 ns ≦ 0 ns ≦ 0 ns] / 10
System time : 0 ns ± 0 ns (0.0 %) [0 ns ≦ 0 ns ≦ 0 ns] / 10
Maximum resident set size : 1.359 MiB ± 0 byte (0.0 %) [1.359 MiB ≦ 1.359 MiB ≦ 1.359 MiB] / 10
Reclaiming a frame page faults: 166.3 ± 0.9 (0.5 %) [166 ≦ 166 ≦ 169] / 10
└─Excluding Outlier : 166 ± 0 (0.0 %) [166 ≦ 166 ≦ 166] / 9(-1)
Involuntary context switches : 3.4 ± 0.663 (19.5 %) [3 ≦ 3 ≦ 5] / 10
└─Excluding Outlier : 3.222 ± 0.416 (12.9 %) [3 ≦ 3 ≦ 4] / 9(-1)
Page size : 16,384 ± 0 (0.0 %) [16,384 ≦ 16,384 ≦ 16,384] / 5
Instructions retired : 3,105,417 ± 2,386 (0.1 %) [3,102,700 ≦ 3,105,224 ≦ 3,109,298] / 5
Cycles elapsed : 1,713,440 ± 362,263 (21.1 %) [1,204,750 ≦ 1,835,156 ≦ 2,095,253] / 5
Peak memory footprint : 896.6 KiB ± 0 byte (0.0 %) [896.6 KiB ≦ 896.6 KiB ≦ 896.6 KiB] / 5
Benchmark #2> sleep '0.9'
LEGEND : Mean ± σ (Coefficient of variation %) [Min ≦ Median ≦ Max] / Valid count
Elapsed (wall clock) time : 900 ms ± 0 ns (0.0 %) [900 ms ≦ 900 ms ≦ 900 ms] / 10
User time : 0 ns ± 0 ns (0.0 %) [0 ns ≦ 0 ns ≦ 0 ns] / 10
System time : 0 ns ± 0 ns (0.0 %) [0 ns ≦ 0 ns ≦ 0 ns] / 10
Maximum resident set size : 1.359 MiB ± 0 byte (0.0 %) [1.359 MiB ≦ 1.359 MiB ≦ 1.359 MiB] / 10
Reclaiming a frame page faults: 166.5 ± 1.025 (0.6 %) [166 ≦ 166 ≦ 169] / 10
└─Excluding Outlier : 166.2 ± 0.629 (0.4 %) [166 ≦ 166 ≦ 168] / 9(-1)
Involuntary context switches : 3.8 ± 0.98 (25.8 %) [3 ≦ 4 ≦ 6] / 10
Page size : 16,384 ± 0 (0.0 %) [16,384 ≦ 16,384 ≦ 16,384] / 5
Instructions retired : 3,104,586 ± 3,725 (0.1 %) [3,099,381 ≦ 3,104,934 ≦ 3,110,136] / 5
Cycles elapsed : 2,058,486 ± 88,114 (4.3 %) [1,960,047 ≦ 2,059,735 ≦ 2,191,571] / 5
Peak memory footprint : 896.6 KiB ± 0 byte (0.0 %) [896.6 KiB ≦ 896.6 KiB ≦ 896.6 KiB] / 5
Benchmark #3> sleep '1.1'
LEGEND : Mean ± σ (Coefficient of variation %) [Min ≦ Median ≦ Max] / Valid count
Elapsed (wall clock) time : 1.1 sec ± 0 ns (0.0 %) [1.1 sec ≦ 1.1 sec ≦ 1.1 sec] / 10
User time : 0 ns ± 0 ns (0.0 %) [0 ns ≦ 0 ns ≦ 0 ns] / 10
System time : 0 ns ± 0 ns (0.0 %) [0 ns ≦ 0 ns ≦ 0 ns] / 10
Maximum resident set size : 1.367 MiB ± 24 KiB (1.7 %) [1.359 MiB ≦ 1.359 MiB ≦ 1.438 MiB] / 10
└─Excluding Outlier : 1.359 MiB ± 0 byte (0.0 %) [1.359 MiB ≦ 1.359 MiB ≦ 1.359 MiB] / 9(-1)
Reclaiming a frame page faults: 166.7 ± 1.792 (1.1 %) [166 ≦ 166 ≦ 172] / 10
└─Excluding Outlier : 166.1 ± 0.314 (0.2 %) [166 ≦ 166 ≦ 167] / 9(-1)
Involuntary context switches : 5.2 ± 2.993 (57.6 %) [3 ≦ 3 ≦ 10] / 10
Page size : 16,384 ± 0 (0.0 %) [16,384 ≦ 16,384 ≦ 16,384] / 5
Instructions retired : 3,122,063 ± 37,238 (1.2 %) [3,098,763 ≦ 3,105,055 ≦ 3,196,271] / 5
Cycles elapsed : 1,795,267 ± 455,814 (25.4 %) [1,182,997 ≦ 2,098,421 ≦ 2,283,568] / 5
Peak memory footprint : 912.6 KiB ± 32 KiB (3.5 %) [896.6 KiB ≦ 896.6 KiB ≦ 976.6 KiB] / 5
└─Excluding Outlier : 896.6 KiB ± 0 byte (0.0 %) [896.6 KiB ≦ 896.6 KiB ≦ 896.6 KiB] / 4(-1)
注意
如果只指定了一个不带参数的命令,则不能指定'command'封装。应使用"--"分隔符。可以混合使用。例如,
# All the same
mntime 'command1 --flag arg' command2 -- 'command3 -f -- args'
mntime 'command1' --flag arg -- command2 -- 'command3 -f -- args'
## Following is recommended
mntime command1 --flag arg -- command2 -- 'command3 -f -- args'
推荐使用"--"分隔符,除非它们包含" -- "。
路线图
- 输出csv和json,以便与其他工具集成。
- 在测量多个命令时显示每个命令的优势。
- 结果的可视化。
查看开放问题,获取提议的功能(以及已知问题)的完整列表。
替代工具
mntime
受hyperfine的启发。
依赖项
直接依赖的crates
cargo license --direct-deps-only --avoid-build-deps --avoid-dev-deps | awk -F ":" 'BEGIN {printf "|License|crate|\n|-|-|\n"} {printf "|%s|%s|\n", $1, $2}'
许可证 | crate |
---|---|
Apache-2.0 或 MIT(7) | anyhow, clap, num-format, once_cell, proc-exit, regex, thiserror |
MIT(3) | crossterm, ratatui, strum |
Zlib(2) | mntime, throbber-widgets-tui |
链式依赖的crates
cargo license --avoid-build-deps --avoid-dev-deps | awk -F ":" 'BEGIN {printf "|License|crate|\n|-|-|\n"} {printf "|%s|%s|\n", $1, $2}'
许可证 | crate |
---|---|
(MIT 或 Apache-2.0) 且 Unicode-DFS-2016(1) | unicode-ident |
Apache-2.0 或 Apache-2.0 WITH LLVM-exception 或 MIT(1) | wasi |
Apache-2.0 或 BSD-2-Clause 或 MIT(2) | zerocopy, zerocopy-derive |
Apache-2.0 或 BSL-1.0(1) | ryu |
Apache-2.0 或 MIT(78) | ahash, allocator-api2, anstream, anstyle, anstyle-parse, anstyle-query, anstyle-wincon, anyhow, arrayvec, bitflags, bitflags, cassowary, cfg-if, clap, clap_builder, clap_derive, clap_lex, colorchoice, either, getrandom, hashbrown, heck, indoc, itertools, itoa, libc, lock_api, log, num-format, once_cell, parking_lot, parking_lot_core, paste, ppv-lite86, proc-exit, proc-macro2, quote, rand, rand_chacha, rand_core, regex, regex-automata, regex-syntax, rustversion, scopeguard, signal-hook, signal-hook-mio, signal-hook-registry, smallvec, static_assertions, syn, syn, thiserror, thiserror-impl, unicode-segmentation, unicode-width, utf8parse, winapi, winapi-i686-pc-windows-gnu, winapi-x86_64-pc-windows-gnu, windows-sys, windows-sys, windows-targets, windows-targets, windows_aarch64_gnullvm, windows_aarch64_gnullvm, windows_aarch64_msvc, windows_aarch64_msvc, windows_i686_gnu, windows_i686_gnu, windows_i686_msvc, windows_i686_msvc, windows_x86_64_gnu, windows_x86_64_gnu, windows_x86_64_gnullvm, windows_x86_64_gnullvm, windows_x86_64_msvc, windows_x86_64_msvc |
MIT(12) | castaway, compact_str, crossterm, crossterm_winapi, lru, mio, ratatui, redox_syscall, stability, strsim, strum, strum_macros |
MIT 或 Unlicense(2) | aho-corasick, memchr |
Zlib(2) | mntime, throbber-widgets-tui |
许可证
"mntime"遵循zlib许可证。请自由使用,但不提供任何保证。
依赖项
~10–17MB
~205K SLoC