Advertisement
devinteske

cmb_test3.sh

Nov 12th, 2018
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.03 KB | None | 0 0
  1. #!/bin/sh
  2. dpv(){ command dpv -k -b "$0" -p "$items\n" -t "$*" -a "\nCombinations:" \
  3.     -l "$total: "; }
  4. items=
  5. for deck in 1 2; do
  6.     for card in A 2 3 4 5 6 7 8 9 10 J Q K; do
  7.         for suit in S H C D; do
  8.             items="$items $card$suit$deck"
  9.         done
  10.     done
  11. done
  12. items="${items# }"
  13. total=$( cmb -tk5 $items )
  14. start=$( date +%s )
  15. trap exit SIGINT
  16. clear
  17. cmb -k5 $items | dpv cmb
  18. end=$( date +%s )
  19. elapsed1=$(( $end - $start ))
  20. seventh=$(( $total / 7 ))
  21. export items
  22. start=$( date +%s )
  23. time echo \
  24.     :$seventh \
  25.     $(( $seventh + 1 )):$seventh \
  26.     $(( $seventh * 2 + 1 )):$seventh \
  27.     $(( $seventh * 3 + 1 )):$seventh \
  28.     $(( $seventh * 4 + 1 )):$seventh \
  29.     $(( $seventh * 5 + 1 )):$seventh \
  30.     $(( $seventh * 6 + 1 )): \
  31.     | xargs -P7 -n1 sh -c '
  32.         start=${1%%:*} count=${1#*:}
  33.         cmb -k5 ${start:+-i$start} ${count:+-c$count} $items
  34.     ' sh | dpv "xargs -P7 cmb"
  35. end=$( date +%s )
  36. elapsed2=$(( $end - $start ))
  37. echo
  38. awk -v e1=$elapsed1 -v e2=$elapsed2 'BEGIN {
  39.     printf "cmb: %us   xargs: %us   opt: %.2fx\n", e1, e2, e1 / (e2 || 1)
  40. }'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement