The function gettimeofday() is not supported on all platforms. Use more portable versions. Adapted from FIPS code.