GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Optimize ``textwrap.indent`` a bit more. · Issue #107424 · python/cpython Closed as not planned Labels 3.13only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement DescriptionThe optimization introduced in #107374 can be improved as follows: Current codeif predicate is None: predicate = lambda s: not s.isspace() prefixed_lines = [] for line in text.splitlines(True): if predicate(line): prefixed_lines.append(prefix) prefixed_lines.append(line) Improved codeprefixed_lines = [] if predicate is None: for line in text.splitlines(True): if not line.isspace(): prefixed_lines.append(prefix) prefixed_lines.append(line) else: for line in text.splitlines(True): if predicate(line): prefixed_lines.append(prefix) prefixed_lines.append(line) Benchmarksimport timeit import textwrap with open("Objects/unicodeobject.c") as f: text = f.read() print(f"indent {len(text.splitlines())} lines.") it = timeit.Timer(lambda: textwrap.indent(text, ' ' * 4)) result = it.repeat(number=1000) result.sort() print(f"{result[0]:.4f}msec")
However the results are very different between two runs (and my laptop may be dying) so I'd like some confirmation from others. Linked PRsActivity
MetadataMetadataAssigneesLabels3.13only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |