Skip to content

Instantly share code, notes, and snippets.

@MrSchism
Last active August 29, 2015 14:22
Show Gist options
  • Save MrSchism/a9b4a9ac54855299dab9 to your computer and use it in GitHub Desktop.
Save MrSchism/a9b4a9ac54855299dab9 to your computer and use it in GitHub Desktop.
The sed/tr showdown
# These are tests to determine which is faster:
# 1. getting the file, fixing it with tr,
# and outputting that to a new file, then deleting the original
# 2. getting the file, and fixing it with sed in-line.
sedtest () {
sedcount=0
echo 'This test is for sed performance'
time (
while [ $sedcount -lt 1000 ]; do
cp ./a.safe ./a
sudo sed -i 's/\r//' ./a
sudo rm ./a
sedcount=$(($sedcount+1))
done
)
}
trtest () {
trcount=0
echo 'This test is for tr/rm performance'
time (
while [ $trcount -lt 1000 ]; do
cp ./a.safe ./a
sudo tr -d '\r' <./a >./b
sudo rm ./a
sudo rm ./b
trcount=$(($trcount+1))
done
)
}
echo ""
echo "This is the sed/tr showdown"
echo "1000 iterations of each process"
echo ""
sedtest
echo ""
trtest
echo ""
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment