Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

python - Are there any datetime.tzinfo implementations in C?

I've been working on a Python library that uses a C extension module to do ISO 8601 parsing.

Part of that work requires the creation of tzinfo objects, which is by far the slowest part of the parse. Calls out to Python implementations of tzinfo (currently pytz.FixedOffset) are simply too slow.

In Python 3.7, datetime.timezone is finally exposed to the C-API. My code takes adavantage of it, and gets a tremendous performance boost from using a C implementation instead of a Python one. I'd love to find a similar C implementation that I could use for Python < 3.6. Perhaps a "backport" of 3.7's datetime.timezone?

I've seen many Python implementations of tzinfo (pytz, datetuil.tz, django.utils.timezone, psycopg2.tz) but none in C.

Are there C implementations of tzinfo (besides datetime.timezone)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

After searching some more, I ended up finding an implementation in Pendulum's low level ISO 8601 parser.

Edit: This implementation was eventually used in my backport of datetime.fromisoformat


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...