nurse / strptime

a fast strptime engine
Other
38 stars 12 forks source link

system time based API #3

Closed mururu closed 9 years ago

mururu commented 9 years ago

Time.strptime uses the current system time as base time, but Strptime#exec dosen't.

Time.strptime("2", "%d") #=> 2015-08-02 00:00:00 +0900
Strptime.new("%d").exec("2") #=> 1970-01-02 00:00:00 +0000

I need an API which uses the current system time as base time. Is it possible? Or does it cause a serious performance degradation?

nurse commented 9 years ago

It sounds reasonable, and gettimeofday of modern OS (RHEL6+) is fast enough. (it should use clock_gettime if exist) gmtime(3) or localtime(3) are also slow but you can cache the value if the given time_t is equal or near enough.

If you create a patch, I'll merge it. If you show a benchmark which says gmtime/localtime cost is low, such trick is not required.

mururu commented 9 years ago

Thanks. I'll try create a patch tomorrow.