speed of repeated localtime() etc.
speed of repeated localtime() etc.
Posted Sep 16, 2023 0:30 UTC (Sat) by jreiser (subscriber, #11027)In reply to: Why glibc's fstat() is slow by brenns10
Parent article: Why glibc's fstat() is slow
Software which appends entries to a log file can call localtime (or its relatives) once per event, and there can be dozens or hundreds of events per second, for instance open(). In most cases the speed of logging can be improved by remembering the headway between the current gettimeofday() and the next future gettimeofday() when the relevant portion of localtime() can change. For an output format of HH:mm:ss, then the headway is limited to at most 1 second. For the local timezone, the minimum headway can be up to 30 minutes. If gettimeofday()still is within the headway, then there is no need to consult any any external authority.
