Repository navigation
Commit 002be51
gh-160725: Speed up print() by looking up write() once per call
Look up the file's write() method once per print() call, instead of once
for each argument, separator and line ending, and pass the cached ' ' and
'\n' strings for the default sep and end directly, instead of converting
them from C strings with PyFile_WriteString(). write() is called exactly
as before.
print() is up to 1.66x faster in pyperf benchmarks, 1.20x geometric
mean; for example, print('a', 1, 2.5) to a file goes from 996 ns to
687 ns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0129ST3GmU89AvSnUNSXu2Yi1 parent 796b26b commit 002be51
2 files changed
Lines changed: 39 additions & 28 deletions
File tree
- Misc/NEWS.d/next/Core_and_Builtins
- Python
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2241 | 2241 | | |
2242 | 2242 | | |
2243 | 2243 | | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
2244 | 2261 | | |
2245 | 2262 | | |
2246 | 2263 | | |
| |||
2264 | 2281 | | |
2265 | 2282 | | |
2266 | 2283 | | |
2267 | | - | |
| 2284 | + | |
2268 | 2285 | | |
2269 | 2286 | | |
2270 | 2287 | | |
| |||
2283 | 2300 | | |
2284 | 2301 | | |
2285 | 2302 | | |
2286 | | - | |
| 2303 | + | |
2287 | 2304 | | |
2288 | 2305 | | |
2289 | 2306 | | |
| |||
2293 | 2310 | | |
2294 | 2311 | | |
2295 | 2312 | | |
2296 | | - | |
| 2313 | + | |
2297 | 2314 | | |
2298 | 2315 | | |
2299 | 2316 | | |
| |||
2303 | 2320 | | |
2304 | 2321 | | |
2305 | 2322 | | |
| 2323 | + | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
2306 | 2328 | | |
2307 | | - | |
2308 | | - | |
2309 | | - | |
2310 | | - | |
2311 | | - | |
2312 | | - | |
2313 | | - | |
2314 | | - | |
2315 | | - | |
2316 | | - | |
2317 | | - | |
| 2329 | + | |
| 2330 | + | |
2318 | 2331 | | |
2319 | | - | |
2320 | | - | |
2321 | | - | |
2322 | | - | |
| 2332 | + | |
| 2333 | + | |
2323 | 2334 | | |
2324 | 2335 | | |
2325 | | - | |
2326 | | - | |
2327 | | - | |
2328 | | - | |
2329 | | - | |
2330 | | - | |
2331 | | - | |
2332 | | - | |
2333 | | - | |
2334 | | - | |
| 2336 | + | |
| 2337 | + | |
2335 | 2338 | | |
| 2339 | + | |
2336 | 2340 | | |
2337 | 2341 | | |
2338 | 2342 | | |
| |||
2343 | 2347 | | |
2344 | 2348 | | |
2345 | 2349 | | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
2346 | 2355 | | |
2347 | 2356 | | |
2348 | 2357 | | |
| |||
0 commit comments