Situation:
I have a C# program which does the following:
- Generate many files (replacing the ones generated last time the program ran.)
- Read those files and perform a time-consuming computation.
Problem:
I only want to perform the time-consuming computation on files which have actually changed since the last time I ran the program.
Solution 1:
- Rename the old file.
- Write the new file.
- Read and compare both files.
This involves writing one file and reading two, which seems like more disk access than necessary.
Solution 2:
- Write to a string instead of a file.
- Read the old file and compare to the string.
- If they are different, overwrite the old file.
This would involve reading one file and possibly writing one, which seems like a big improvement over my first idea.
Question:
Can you describe a better way to solve my problem? (and explain why it is better?)