Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the random-bytes benchmark #595

Merged
merged 2 commits into from
Sep 8, 2023
Merged

add the random-bytes benchmark #595

merged 2 commits into from
Sep 8, 2023

Conversation

amtoine
Copy link
Member

@amtoine amtoine commented Sep 8, 2023

related to

this adds the following command to the benchmarks

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
}

and runs it a bunch of times.

example output

> nu benchmarks/random-bytes.nu
╭───┬──────────────────────────────────────┬────────╮
 # │                 time                 │   n    │
├───┼──────────────────────────────────────┼────────┤
 0  4ms 224µs 690ns +/- 748µs 111ns           10 
 1  3ms 943µs 418ns +/- 527µs 64ns           100 
 2  5ms 253µs 628ns +/- 503µs 133ns         1000 
 3  15ms 434µs 510ns +/- 538µs 919ns       10000 
 4  170ms 617µs 135ns +/- 3ms 747µs 98ns  100000 
╰───┴──────────────────────────────────────┴────────╯

@fdncred fdncred merged commit 0dd9717 into nushell:main Sep 8, 2023
@fdncred
Copy link
Collaborator

fdncred commented Sep 8, 2023

Thanks

@amtoine amtoine deleted the benchmarks branch September 8, 2023 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants