Skip to content

Commit

Permalink
add the random-bytes benchmark (nushell#595)
Browse files Browse the repository at this point in the history
* add the `random-bytes` benchmark

* add report
  • Loading branch information
amtoine authored Sep 8, 2023
1 parent 411496d commit 0dd9717
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions benchmarks/random-bytes.nu
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0dd9717

Please sign in to comment.