Skip to content

Commit da47990

Browse files
committed
add some documentation with examples to std bench
1 parent 65d0f14 commit da47990

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

crates/nu-std/lib/mod.nu

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,43 @@ def "from ns" [] {
154154
[$in "ns"] | str join | into duration
155155
}
156156

157-
# TODO
157+
# run a piece of `nushell` code multiple times and measure the time of execution.
158+
#
159+
# this command returns a benchmark report of the following form:
160+
# ```
161+
# record<
162+
# mean: duration
163+
# std: duration
164+
# times: list<duration>
165+
# >
166+
# ```
167+
#
168+
# > **Note**
169+
# > `std bench --pretty` will return a `string`.
170+
#
171+
# # Examples
172+
# measure the performance of simple addition
173+
# > std bench { 1 + 2 } -n 10
174+
# ╭───────┬────────────────────╮
175+
# │ mean │ 4µs 956ns │
176+
# │ std │ 4µs 831ns │
177+
# │ │ ╭───┬────────────╮ │
178+
# │ times │ │ 0 │ 19µs 402ns │ │
179+
# │ │ │ 1 │ 4µs 322ns │ │
180+
# │ │ │ 2 │ 3µs 352ns │ │
181+
# │ │ │ 3 │ 2µs 966ns │ │
182+
# │ │ │ 4 │ 3µs │ │
183+
# │ │ │ 5 │ 3µs 86ns │ │
184+
# │ │ │ 6 │ 3µs 84ns │ │
185+
# │ │ │ 7 │ 3µs 604ns │ │
186+
# │ │ │ 8 │ 3µs 98ns │ │
187+
# │ │ │ 9 │ 3µs 653ns │ │
188+
# │ │ ╰───┴────────────╯ │
189+
# ╰───────┴────────────────────╯
190+
#
191+
# get a pretty benchmark report
192+
# > std bench { 1 + 2 } --pretty
193+
# 3µs 125ns +/- 2µs 408ns
158194
export def bench [
159195
code: closure # the piece of `nushell` code to measure the performance of
160196
--rounds (-n): int = 50 # the number of benchmark rounds (hopefully the more rounds the less variance)

0 commit comments

Comments
 (0)