3

Assuming I want to recompile some files only if they've changed, is using the file modification time a reliable source? I know a lot of people use hashes, but is that really necessary?

Does this depend on the OS or file system?

If a file is "touched" but not modified, it's not a big deal, as long as the mod time is always updated when it is modified.

mpen
  • 272,448
  • 266
  • 850
  • 1,236

1 Answers1

0

The choice of what files to compile and which ones not has a lot to do with machine performance and compilation and linkage tool efficiency. If a project has a huge number of files and a project build takes hours you obviously want to exclude as many files as possible that do not require re-build. On the other hand for simple smaller projects it may be feasible to just process all files fully every time.

For projects that lie between these extremes it becomes necessary to look at how much time it takes the machine to process simple date mod comparisons versus computing hashes and comparing those. Also it is important to compare the hash processing time to the time it takes to send the same file through the build steps. If these latter times even approach a ratio of 1::2 you may be better off just sticking to the simple file mod date methods.

Michael Karas
  • 248
  • 2
  • 12
  • I'm assuming that checking mod dates is O(1) and hashes, although slower, should be significantly faster than compiling an entire file. You haven't given any reason prefer hashes over mod dates; why wouldn't I do that *always*? – mpen Jun 04 '14 at 22:59
  • @Mark - I didn't give a preference because I suggested that the is actually one of a performance question. Compare the amount of time to diddle with the file dates as opposed to computing hashes on those same files. – Michael Karas Jun 05 '14 at 02:41
  • 1
    @Mark - In a build system you are normally not comparing file contents at all. What you really are comparing some attribute of the files against the corresponding build products/results of the build process. For example with dates you compare source file dates to object file dates or object dates to executable dates. Typically with hashes you capture and save a hash of each file as it is used in the build process. Next build you compare the file's newly computed hash to the previously stored hash value. – Michael Karas Jun 05 '14 at 02:45