The best way to compare text files is with the diff command:
diff output1.txt output1.txt
For a mass comparison, you can call diff in a loop:
for x in input*.txt; do
slow-program <"$x" >"$x.out-slow"
fast-program <"$x" >"$x.out-fast"
diff "$x.out-slow" "$x.out-fast"
done
If the snippet above produces any output, your fast program is buggy. In bash/ksh/zsh, you don't need to store the intermediate files on the disk. However this is not necessarily a good thing since it is likely to be useful to inspect the differing output at your leisure.
for x in input*.txt; do
diff <(slow-program <"$x") <(fast-program <"$x")
done
It may be more convenient to put inputs and outputs in separate directories and perform a recursive diff.
for x in inputs/*; do slow-program <"$x" >"slow/${x##*/}"; done
for x in inputs/*; do fast-program <"$x" >"fast/${x##*/}"; done
diff -ru slow fast
My recommendation would be to write a makefile that runs the tests and performs the comparisons (in separate targets). (Use tabs where I put 8 spaces.)
all_test_inputs = $(wildcard input*.txt) # relies on GNU make
%.out-slow: %.txt slow-program
./slow-program <$< >$@.tmp
mv $@.tmp $@
%.out-fast: %.txt fast-program
./fast-program <$< >$@.tmp
mv $@.tmp $@
%.diff: %.out-slow %.out-fast
-diff $*.out-slow $*.out-fast >$@.tmp
mv $@.tmp $@
# Test that all diff files are empty
test: $(all_test_inputs:%.txt=%.diff)
for x in $^; do ! test -s "$x"; done
.PHONY: test
Run make test to process all the input files (only for the input files or the programs that have changed since the last time) and compare results. The command will be successful if and only if all the tests ran correctly and the output of both programs are identical in each case.