#!/bin/sh
shopt -s globstar dotglob
ulimit -s unlimited
time ltrep -H '\s*struct\s+[a-z_]+\s*\{%' linux/** 2>/dev/null > ltrep.out
time rg --no-unicode --no-ignore --hidden -L -a '^\s*struct\s+[a-z_]+\s*\{' linux/ > rg.out
time LC_ALL=C grep -R -a -E '^\s*struct\s+[a-z_]+\s*\{' linux/ > grep.out
diff <(sort rg.out)    <(sort grep.out)
diff <(sort ltrep.out) <(sort grep.out)
diff <(sort ltrep.out) <(sort rg.out)
rm ltrep.out rg.out grep.out

# sh-5.2$ git clone https://github.com/torvalds/linux.git --depth 1
# Cloning into 'linux'...
# remote: Enumerating objects: 100874, done.
# remote: Counting objects: 100% (100874/100874), done.
# remote: Compressing objects: 100% (89526/89526), done.
# remote: Total 100874 (delta 10561), reused 95432 (delta 10293), pack-reused 0 (from 0)
# Receiving objects: 100% (100874/100874), 280.20 MiB | 4.40 MiB/s, done.
# Resolving deltas: 100% (10561/10561), done.
# Updating files: 100% (95299/95299), done.
# sh-5.2$ ~/ltrep\ ripgrep\ grep\ struct\ perf\ test.sh
#
# real	0m3.249s
# user	0m2.092s
# sys	0m1.115s
#
# real	0m0.475s
# user	0m0.619s
# sys	0m1.143s
#
# real	0m1.589s
# user	0m0.987s
# sys	0m0.601s
#
# I'm happy with that
# we can see `grep -r` is single-threaded because user+sys=real
# ripgrep's user+sys is 1.762 which is... slower than grep. hmm
# ltrep (via shell globbing) is only 2x slower which is pretty good

# srcs:
# https://youtu.be/UJ_W0O3sFnY
# man rg
# man grep
# https://askubuntu.com/questions/829796/how-should-i-glob-for-all-hidden-files-except-and
# https://unix.stackexchange.com/questions/49913/recursive-glob
# https://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1
# https://stackoverflow.com/questions/714421/what-is-an-easy-way-to-do-a-sorted-diff-between-two-files

