Opened 7 years ago
Closed 5 years ago
#11806 closed Bugs (wontfix)
microsec_clock::universal_time() is needlessly slow
Reported by: | Owned by: | James E. King, III | |
---|---|---|---|
Milestone: | To Be Determined | Component: | date_time |
Version: | Boost 1.55.0 | Severity: | Optimization |
Keywords: | Cc: |
Description
The documentation for microsec_clock::universal_time()
says:
Get the UTC time using a sub second resolution clock. On Unix systems this is implemented using GetTimeOfDay.
In fact it is implemented partly using gettimeofday()
but also gmtime_r()
. Once you unwrap all the layers, the flow is something like this:
sec,nsec = gettimeofday() date,time = gmtime(sec) sec,nsec = ptime(date,time) return sec+nsec/1000
The problem is that gmtime_r()
is very slow, relative to the other operations involved here, and it is completely unnecessary. A call to gettimeofday()
on Unix is all you need to implement universal_time()
.
Change History (2)
comment:1 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 5 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
I benchmarked calling the current implementation (boost 1.66.0) in release mode on linux (ubuntu artful) 1M times and each call takes less than 100ns:
I then changed the code such that if the clock source is universal time (i.e. gmtime_r) passed into create_time, we take (what I thought would be a) shortcut:
This slowed down the program so much I didn't even let it finish. Asking for a ptime based on a large number of seconds is incredibly inefficient. So I am resolving this as wontfix, unless you have a better suggestion for implementing it.