Opened 11 years ago

Closed 11 years ago

#21052 closed Cleanup/optimization (fixed)

force_bytes should handle the common case first like force_text

Reported by: Aymeric Augustin Owned by: nobody
Component: Utilities Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The patch I'm about to commit makes force_bytes twice as fast in the common case — and twice as slow when it's called with a memoryview, but we don't use them that often in Django.

Before:

% python -m timeit -s 'from django.utils.encoding import force_bytes' 'force_bytes(b"")' ~/Documents/dev/django
1000000 loops, best of 3: 0.705 usec per loop

After:

% python -m timeit -s 'from django.utils.encoding import force_bytes' 'force_bytes(b"")' ~/Documents/dev/django
1000000 loops, best of 3: 0.376 usec per loop

Change History (1)

comment:1 by Aymeric Augustin <aymeric.augustin@…>, 11 years ago

Resolution: fixed
Status: newclosed

In b80be68e088f56f5b2ab5371b92a478a14937e8b:

Fixed #21052 -- Small performance optimization.

Note: See TracTickets for help on using tickets.
Back to Top