Created
August 23, 2012 17:38
-
-
Save hauleth/3439252 to your computer and use it in GitHub Desktop.
Script for comparing I/O in stdlib and iostreams.
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
#!/bin/sh | |
times=1000000 # count | |
main="int main(){" | |
loop=" for(int i = 0; i < $times; i++) " | |
end=" return 0;}" | |
CXX=g++ | |
FLAGS=-O2 | |
file=test.cpp # outfile | |
ofile=test.out # executable outfile | |
ifile=test.in # infile | |
if [ ! -e $ifile ] | |
then | |
seq 0 $powt > $ifile | |
fi | |
echo "Output:" | |
echo -e "#include<iostream> \n$main $loop std::cout << i;$end" > $file | |
echo "std::cout bez sync_with_stdio(0)" | |
$CXX -o $ofile $file $FLAGS | |
time ./$ofile > /dev/null | |
echo -e "#include<iostream> \n$main std::ios_base::sync_with_stdio(0); $loop std::cout << i;$end" > $file | |
echo -e "\nstd::cout z sync_with_stdio(0)" | |
$CXX -o $ofile $file $FLAGS | |
time ./$ofile > /dev/null | |
echo -e "#include<cstdio> \n$main $loop printf(\"%d\", i);$end" > $file | |
echo -e "\nprintf()" | |
$CXX -o $ofile $file $FLAGS | |
time ./$ofile > /dev/null | |
echo -en "\nOutput:" | |
echo -e "#include<iostream> \n$main int test; $loop { std::cin >> test;}$end" > $file | |
echo -e "\nstd::cin bez sync_with_stdio(0)" | |
$CXX -o $ofile $file $FLAGS | |
time ./$ofile < $ifile | |
echo -e "#include<iostream> \n$main std::ios_base::sync_with_stdio(0); int test; $loop { std::cin >> test;}$end" > $file | |
echo -e "\nstd::cin z sync_with_stdio(0)" | |
$CXX -o $ofile $file $FLAGS | |
time ./$ofile < $ifile | |
echo -e "#include<cstdio> \n$main int test; $loop { scanf(\"%d\", &i);}$end" > $file | |
echo -e "\nscanf()" | |
g++ -o $ofile $file $FLAGS | |
time ./$ofile < $ifile | |
rm $ofile $ifile #file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment