Last active
August 29, 2015 14:22
-
-
Save MrSchism/a9b4a9ac54855299dab9 to your computer and use it in GitHub Desktop.
The sed/tr showdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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