mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 07:07:46 +00:00
add the random-bytes
benchmark (#595)
* add the `random-bytes` benchmark * add report
This commit is contained in:
parent
411496d311
commit
0dd97178ad
1 changed files with 20 additions and 0 deletions
20
benchmarks/random-bytes.nu
Normal file
20
benchmarks/random-bytes.nu
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use std bench
|
||||||
|
|
||||||
|
def "random bytes" [n: int]: nothing -> binary {
|
||||||
|
seq 1 ($n / 8 + 1)
|
||||||
|
| each { random integer }
|
||||||
|
| into binary
|
||||||
|
| enumerate
|
||||||
|
| reduce -f 0x[] {|it, acc|
|
||||||
|
$acc | bytes add $it.item
|
||||||
|
}
|
||||||
|
| first $n
|
||||||
|
}
|
||||||
|
|
||||||
|
let ns = [10, 100, 1_000, 10_000, 100_000]
|
||||||
|
|
||||||
|
let report = $ns | each {|n|
|
||||||
|
bench { random bytes $n } --rounds 10 --pretty --verbose
|
||||||
|
} | wrap time | merge ($ns | wrap n)
|
||||||
|
|
||||||
|
$report
|
Loading…
Add table
Add a link
Reference in a new issue