mirror of
https://github.com/nushell/nu_scripts.git
synced 2024-08-18 01:40:30 +03:00
Nupass par each threads 20230504 (#477)
* Update ReadMe.md Added explanation of how to use new --threads switch to feed to the par-each loops * Update nupass.nu Added --threads flag to allow setting of same in par-each loops, for performance fine tuning
This commit is contained in:
parent
5b6d20d0bd
commit
f02f4dd0d0
@ -20,11 +20,12 @@ http get https://raw.githubusercontent.com/RickCogley/jpassgen/master/genpass-di
|
||||
let dictfile = $"/path/to/my/genpass-dict-jp"
|
||||
```
|
||||
|
||||
5. Confirm and edit the default symbols list and diceware delimiter:
|
||||
5. In the main function's flags section, confirm and edit the default symbols list, diceware delimiter and threads for par-each (double the number of your CPU cores seems to be a good sweet spot):
|
||||
|
||||
```
|
||||
--symbols (-s): string = "!@#$%^&()_-+[]{}" # Symbols to use in password
|
||||
--delimiter (-m): string = "-" # Delimiter for diceware
|
||||
--threads (-t): int = 16 # Number of threads to use in par-each
|
||||
```
|
||||
|
||||
6. Load the script with `use` in your `config.nu`, something like:
|
||||
@ -64,7 +65,15 @@ std bench --rounds 10 --verbose {nupass 100 -v diceware}
|
||||
std bench --rounds 10 --verbose {nupass 1000 -v mixnmatch}
|
||||
```
|
||||
|
||||
If you change the `par-each` to `each` in the main list builders for instance, you'll see a significant performance hit. When I benchmarked `nupass 100`, using just `each` took 7 sec per round, whereas changing to `par-each` dropped that to about 1 sec per round.
|
||||
If you change the `par-each` to `each` in the main list builders for instance, you'll see a significant performance hit. When I benchmarked `nupass 100`, using just `each` took 7 sec per round, whereas changing to `par-each` dropped that to about 1 sec per round.
|
||||
|
||||
You can tweak it a little further by setting the threads for par-each.
|
||||
|
||||
```
|
||||
std bench --rounds 10 --verbose {nupass 100 -v diceware -t 8}
|
||||
std bench --rounds 10 --verbose {nupass 100 -v diceware -t 16}
|
||||
std bench --rounds 10 --verbose {nupass 100 -v diceware -t 32}
|
||||
```
|
||||
|
||||
<img width="736" alt="image" src="https://user-images.githubusercontent.com/512328/235553238-48b48f37-0eae-48d3-8afe-e17515cd8325.png">
|
||||
|
||||
@ -81,4 +90,3 @@ This command doesn't let you specify a precise length.
|
||||
Thanks everyone on Discord for putting up with and answering my nubie questions @amtoine, @fdncred, @jelle, @sygmei, @kubouch and for the feedback after try number 1.
|
||||
|
||||
<img width="576" alt="image" src="https://user-images.githubusercontent.com/512328/235383307-d3f3d65d-c184-4dfa-9fe9-677b677d8531.png">
|
||||
|
||||
|
@ -2,12 +2,13 @@
|
||||
# Author: @rickcogley
|
||||
# Thanks: @amtoine, @fdncred, @jelle, @sygmei, @kubouch
|
||||
# Updates: 20230415 - initial version
|
||||
# 20230416 - added @amtoine's slick probabilistic "random decimal" char capitalization
|
||||
# 20230417 - added script duration output in debug block
|
||||
# 20230421 - added length of symbol chars to get-random-symbol function
|
||||
# 20230422 - added variant flag to generate different styles of passwords
|
||||
# 20230416 - add @amtoine's slick probabilistic "random decimal" char capitalization
|
||||
# 20230417 - add script duration output in debug block
|
||||
# 20230421 - add length of symbol chars to get-random-symbol function
|
||||
# 20230422 - add 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
|
||||
# 20230503 - add threads flag for fine tuning par-each
|
||||
|
||||
#======= NUPASS PASSWORD GENERATOR =======
|
||||
# Generate password of 3 dictionary file words, numbers and symbols
|
||||
@ -17,6 +18,7 @@ export def main [
|
||||
--symbols (-s): string = "!@#$%^&()_-+[]{}" # Symbols to use in password
|
||||
--variant (-v): string = "regular" # Password style to generate in regular, mixnmatch, alphanum, alpha, diceware
|
||||
--delimiter (-m): string = "-" # Delimiter for diceware
|
||||
--threads (-t): int = 16 # Number of threads to use in par-each
|
||||
--debug (-d) # Include debug info
|
||||
] {
|
||||
##### Main function #####
|
||||
@ -30,15 +32,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 | par-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 } --threads $threads)
|
||||
|
||||
# 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 | par-each { |i| $symbols | get-random-symbol $symbols $symbols_len })
|
||||
let random_symbols = (1..$words | par-each { |i| $symbols | get-random-symbol $symbols $symbols_len } --threads $threads)
|
||||
|
||||
# Get some random numbers
|
||||
let random_numbers = (1..$words | par-each { |i| (random integer 0..99) })
|
||||
let random_numbers = (1..$words | par-each { |i| (random integer 0..99) } --threads $threads)
|
||||
|
||||
# Print some vars if debug flag is set
|
||||
if $debug {
|
||||
|
Loading…
Reference in New Issue
Block a user