Concurrent scanstring + encode_basestring_ascii (module-level).
()
| 424 | |
| 425 | |
| 426 | def scenario_module_functions(): |
| 427 | """Concurrent scanstring + encode_basestring_ascii (module-level).""" |
| 428 | scanstring = _speedups.scanstring |
| 429 | enc_ascii = _speedups.encode_basestring_ascii |
| 430 | |
| 431 | strings_to_encode = [ |
| 432 | "hello world", |
| 433 | "\"quoted\" with \\ backslash", |
| 434 | "\u00e9\u00e8\u00ea \u4e2d\u6587 emoji-\U0001F600", |
| 435 | "control\n\t\r chars", |
| 436 | "x" * 256, |
| 437 | ] |
| 438 | # For scanstring: the opening quote has been consumed; pass end=1. |
| 439 | scan_sources = [ |
| 440 | r'"a simple string"', |
| 441 | r'"with \"escapes\" and \n newlines"', |
| 442 | r'"unicode \u00e9\u00e8\u4e2d\u6587 stuff"', |
| 443 | r'"backslashes \\ and slashes \/"', |
| 444 | ] |
| 445 | |
| 446 | def enc_worker(): |
| 447 | deadline = time.monotonic() + DURATION |
| 448 | for i in range(ITERATIONS): |
| 449 | try: |
| 450 | enc_ascii(strings_to_encode[i % len(strings_to_encode)]) |
| 451 | except Exception: |
| 452 | pass |
| 453 | if time.monotonic() > deadline: |
| 454 | break |
| 455 | |
| 456 | def scan_worker(): |
| 457 | deadline = time.monotonic() + DURATION |
| 458 | for i in range(ITERATIONS): |
| 459 | src = scan_sources[i % len(scan_sources)] |
| 460 | try: |
| 461 | # scanstring(basestring, end, encoding, strict) |
| 462 | scanstring(src, 1, "utf-8", 1) |
| 463 | except Exception: |
| 464 | pass |
| 465 | if time.monotonic() > deadline: |
| 466 | break |
| 467 | |
| 468 | half = max(THREADS // 2, 1) |
| 469 | run_scenario( |
| 470 | "module-level scanstring + encode_basestring_ascii", |
| 471 | [enc_worker, scan_worker], |
| 472 | [half, max(THREADS - half, 1)], |
| 473 | ) |
| 474 | |
| 475 | |
| 476 | # --------------------------- main ------------------------------------------- # |
nothing calls this directly
no test coverage detected
searching dependent graphs…