Skip to content

Instantly share code, notes, and snippets.

@s-leroux
Created October 1, 2018 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-leroux/e12358746565de4ec84f59a94d505a9e to your computer and use it in GitHub Desktop.
Save s-leroux/e12358746565de4ec84f59a94d505a9e to your computer and use it in GitHub Desktop.
A quick and dirty script to compare performances between passing an input file as a `file parameter`, as a `redirection` or using an `useless cat`
DATAFILE="${HOME}/random.data"
SCRIPT="
{
/* simulate some processing */
for(i = 0; i < rand()*1000; ++i)
acc += i;
}
"
for n in {00..99}; do
# Generate few MB of data
dd if=/dev/urandom of="${DATAFILE}" bs=1M count=500 conv=fdatasync oflag=nocache
# Drop cache
dd of="${DATAFILE}" count=0 conv=notrunc,fdatasync oflag=nocache
echo -e '\nA'
time \
awk "${SCRIPT}" "${DATAFILE}"
# Drop cache
dd of="${DATAFILE}" count=0 conv=notrunc,fdatasync oflag=nocache
echo -e '\nB'
time \
awk "${SCRIPT}" < "${DATAFILE}"
# Drop cache
dd of="${DATAFILE}" count=0 conv=notrunc,fdatasync oflag=nocache
echo -e '\nC'
time cat "${DATAFILE}" | \
awk "${SCRIPT}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment