astropy: Time creation for unix time is very slow
This issue is very likely related to #5846 and #10167.
When using astropy.time.Time
to convert unix timestamps (or utime) to datetime, it’s more than factor 1000 slower than using datetime.utcfromtimestamp()
.
I benchmarked converting 2000 values, which is not even much when reading fits files
Time(times[i], format="unix") # 1.61s
datetime.utcfromtimestamp(times[i]) # 998µs
Time(times[i], format="utime") # 1.74s
datetime.utcfromtimestamp(times[i] + offset) # 2ms, offset being set to Time(0, format="utime").to_value("unix")
Astropy does some special checks for leap seconds and so on, but I haven’t found an example where the native conversion differs from astropy using seconds as the smallest unit… is there any at all? If not, would it be feasible to convert those two formats using the native datetime
module? If not, what is causing this huge difference…? seems a bit strange to me
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (14 by maintainers)
@Laubeee, @taldcroft - It seems easier to have new issues rather than have people read through all of the above, so I opened #10596 and #10597 about the two points resulting from our discussion. I’ll close this one now; feel free to add to the two issues (or re-open this one if I missed something!).