Skip to content

Use locale.nl_langinfo in _strptime.py #53161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
brettcannon opened this issue Jun 6, 2010 · 7 comments
Open

Use locale.nl_langinfo in _strptime.py #53161

brettcannon opened this issue Jun 6, 2010 · 7 comments
Assignees
Labels
performance Performance or resource usage stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@brettcannon
Copy link
Member

BPO 8915
Nosy @abalkin

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/abalkin'
closed_at = None
created_at = <Date 2010-06-06.03:35:08.311>
labels = ['3.7', 'type-feature', 'library']
title = 'Use locale.nl_langinfo in _strptime'
updated_at = <Date 2016-09-10.18:34:48.582>
user = 'https://github.com/brettcannon'

bugs.python.org fields:

activity = <Date 2016-09-10.18:34:48.582>
actor = 'belopolsky'
assignee = 'belopolsky'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2010-06-06.03:35:08.311>
creator = 'brett.cannon'
dependencies = []
files = []
hgrepos = []
issue_num = 8915
keywords = []
message_count = 3.0
messages = ['107181', '107445', '125958']
nosy_count = 1.0
nosy_names = ['belopolsky']
pr_nums = []
priority = 'low'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue8915'
versions = ['Python 3.7']

@brettcannon
Copy link
Member Author

It might perform better to use locale.nl_langinfo to get the current locale's datetime information instead of reverse-engineering from strftime (need to benchmark to see if this is true). This would need to be conditional as the datetime info might not be exposed through nl_langinfo.

@brettcannon brettcannon added the stdlib Python modules in the Lib dir label Jun 6, 2010
@abalkin
Copy link
Member

abalkin commented Jun 10, 2010

See also bpo-8957. If this happens, I would like to add a pure python implementation strftime. See also bpo-7989.

@abalkin abalkin self-assigned this Jun 10, 2010
@abalkin
Copy link
Member

abalkin commented Jan 10, 2011

I would also like to consider using OS strptime on platforms with a decent implementation.

@abalkin abalkin added the type-feature A feature request or enhancement label Jan 10, 2011
@abalkin abalkin added the 3.7 (EOL) end of life label Sep 10, 2016
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@serhiy-storchaka serhiy-storchaka self-assigned this Oct 11, 2024
@StanFromIreland
Copy link
Contributor

StanFromIreland commented Mar 16, 2025

Not fully possible, nl_langinfo doesn't support LC_TIME.

We can partially use it, ~33% faster.

def _getlang():
    lang = locale.setlocale(locale.LC_TIME, None)
    encoding = locale.nl_langinfo(locale.CODESET)

    return lang, encoding
$ python3.14 -m timeit -s "from _strptime import _getlang" "_getlang()"
1000000 loops, best of 5: 298 nsec per loop
$ ./python -m timeit -s "from _strptime import _getlang" "_getlang()"
1000000 loops, best of 5: 203 nsec per loop                    # ~33% faster

Caching the information will result in a decent performance gain.

@StanFromIreland
Copy link
Contributor

I would also like to consider using OS strptime on platforms with a decent implementation.

This should be a separate issue.

@picnixz picnixz added extension-modules C modules in the Modules dir and removed 3.7 (EOL) end of life labels Mar 16, 2025
@StanFromIreland
Copy link
Contributor

StanFromIreland commented Mar 16, 2025

@picnixz _strptime is currently pure python. This does not need the extension-modules label. It does however need the performance label :-)

@picnixz picnixz changed the title Use locale.nl_langinfo in _strptime Use locale.nl_langinfo in _strptime.py Mar 16, 2025
@picnixz picnixz added performance Performance or resource usage and removed extension-modules C modules in the Modules dir labels Mar 16, 2025
@picnixz
Copy link
Member

picnixz commented Mar 16, 2025

I never know which part of the date/time API is duplicated in C and which one is not so thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
Status: No status
Development

No branches or pull requests

5 participants