Timing seems to be str.islower much more efficient, so you need more than just overhead:
python2:
In [68]: timeit islower("f") 1000000 loops, best of 3: 641 ns per loop In [69]: timeit "f".islower() 10000000 loops, best of 3: 50.5 ns per loop
python3
In [2]: timeit "f".islower() 10000000 loops, best of 3: 58.7 ns per loop In [3]: timeit islower("f") 1000000 loops, best of 3: 801 ns per loop
One difference / advantage is that you actually do not need to throw the str object, you can pass either a single character string or an integer.
In [38]: ascii.islower(97) Out[38]: True
But using chr with str.lower even more efficient:
In [51]: timeit ascii.islower(122) 1000000 loops, best of 3: 583 ns per loop In [52]: timeit chr(122).islower() 10000000 loops, best of 3: 122 ns per loop
The only curses link howto documentation describes the use of curses.ascii , how this can be useful when using the curses
while 1: c = stdscr.getch() if c == ord('p'): PrintDocument() elif c == ord('q'): break
The curses.ascii module provides ASCII class membership functions that accept either integer or 1-character arguments; they can be useful in writing more readable tests for your command interpreters. It also provides conversion functions that accept either integer or 1-digit string arguments and return the same type.
I think it will be difficult for you to find any advantage using ascii.islower over str.islower outside of anything related to the curses module.
source share