3 ms·
> 2. Compilers will always modify the timestamps on every file they are expected to output : if a write happens why not update mtime? nanosecond precision, what
by tzs 6y ago
> 2. Compilers will always modify the timestamps on every file they are expected to output : if a write happens why not update mtime? nanosecond precision, what year is it?
It has nanosecond precision, but on most systems it does not have nanosecond resolution.
$ touch a1; sleep .0001; touch a2; stat a1 a2 | grep Modify:
Modify: 2020-07-18 21:37:56.421487075 +0000
Modify: 2020-07-18 21:37:56.421487075 +0000
$ touch a1; sleep .0001; touch a2; stat a1 a2 | grep Modify:
Modify: 2020-07-18 21:37:57.397502229 +0000
Modify: 2020-07-18 21:37:57.397502229 +0000
$ touch a1; sleep .0001; touch a2; stat a1 a2 | grep Modify:
Modify: 2020-07-18 21:37:58.273515840 +0000
Modify: 2020-07-18 21:37:58.277515902 +0000
$ touch a1; sleep .0001; touch a2; stat a1 a2 | grep Modify:
Modify: 2020-07-18 21:41:00.736348218 +0000
Modify: 2020-07-18 21:41:00.736348218 +0000
$ touch a1; sleep .0001; touch a2; stat a1 a2 | grep Modify:
Modify: 2020-07-18 21:41:01.708363288 +0000
Modify: 2020-07-18 21:41:01.708363288 +0000
$ touch a1; sleep .0001; touch a2; stat a1 a2 | grep Modify:
Modify: 2020-07-18 21:41:02.504375653 +0000
Modify: 2020-07-18 21:41:02.508375715 +0000
Note that the difference is either 0 or 0.004000062. This is on a Debian 9 system running on an Amazon Lightsail instance with an ext4 filesystem.
Here's a quick and dirty script to play with this:
C=0
R=0
while :
do
R=$((R+1))
touch a1; sleep $1; touch a2
T1=$(stat a1 | grep Modify | sed -e 's/.*://' | sed -e 's/ .*//')
T2=$(stat a2 | grep Modify | sed -e 's/.*://' | sed -e 's/ .*//')
if [ $T1 != $T2 ]; then
dc <<HERE
20k $T2 $T1 - p
HERE
C=$((C+1))
if [ $C -eq 100 ]; then
echo "$R runs"
exit 0
fi
fi
done
Output on the above system:
$ bash t.sh 0.001 | sort | uniq -c
4 .004000061
83 .004000062
13 .004000063
1 222 runs
and on a VMWare Fusion VM running Debian 8 on my Mac:
$ bash t.sh 0.001 | sort | uniq -c
29 .003999599
44 .003999600
27 .003999601
1 323 runs
- sabujp 6y agoahh yea thanks for the reminder, i think bazel also hashes all inputs and outputs