1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-05 08:37:46 +00:00

Nupass performance 20230502 (#474)

* Use par-each in main list builders

Using par-each on the main list builders for random words, symbols and numbers results in a significant performance gain

* Add benchmarking section

Explain how par-each really can improve performance
This commit is contained in:
Rick Cogley 2023-05-02 20:39:33 +09:00 committed by GitHub
parent 112d8b2f7e
commit afba27f304
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View file

@ -7,6 +7,7 @@
# 20230421 - added length of symbol chars to get-random-symbol function
# 20230422 - added variant flag to generate different styles of passwords
# 20230501 - refactor to allow number of words to be specified, use list manipulation and reduce to string
# 20230502 - improve performance on list builders with par-each
#======= NUPASS PASSWORD GENERATOR =======
# Generate password of 3 dictionary file words, numbers and symbols
@ -29,15 +30,15 @@ export def main [
let num_lines = (open ($dictfile) | lines | wrap word | upsert len {|it| $it.word | split chars | length} | where len <= ($word_length) | length)
# Get random words from dictionary file
let random_words = (1..$words | each { |i| $dictfile | get-random-word $word_length $num_lines | random-format-word })
let random_words = (1..$words | par-each { |i| $dictfile | get-random-word $word_length $num_lines | random-format-word })
# Get some symbols to sprinkle like salt bae
# Update default symbol chars in symbols flag
let symbols_len = ($symbols | str length)
let random_symbols = (1..$words | each { |i| $symbols | get-random-symbol $symbols $symbols_len })
let random_symbols = (1..$words | par-each { |i| $symbols | get-random-symbol $symbols $symbols_len })
# Get some random numbers
let random_numbers = (1..$words |each { |i| (random integer 0..99) })
let random_numbers = (1..$words | par-each { |i| (random integer 0..99) })
# Print some vars if debug flag is set
if $debug {