|
1 | | -# Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. |
| 1 | +# Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. |
2 | 2 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 | 3 | # |
4 | 4 | # The Universal Permissive License (UPL), Version 1.0 |
|
43 | 43 | import os |
44 | 44 |
|
45 | 45 |
|
46 | | -PYC_BYTES = [] |
47 | | - |
48 | | - |
49 | | -def initialize_pyc_bytes(): |
50 | | - dirname = os.path.dirname(__file__) |
51 | | - for filename in os.listdir(dirname): |
52 | | - if filename.endswith(".py"): |
53 | | - filepath = os.path.join(dirname, filename) |
54 | | - with io.open_code(filepath) as f: |
55 | | - PYC_BYTES.append(marshal.dumps(compile(f.read(), filename, "exec"))) |
56 | | - |
57 | | - |
58 | | -initialize_pyc_bytes() |
59 | | -del initialize_pyc_bytes |
| 46 | +with io.open_code(os.path.join(os.path.dirname(__file__), "unmarshal-pyc.txt")) as f: |
| 47 | + PYC_BYTES = marshal.dumps(compile(f.read() * 1000, "pyc", "exec")) |
60 | 48 |
|
61 | 49 |
|
62 | 50 | def measure(inner_iterations=1): |
63 | | - for _ in range(inner_iterations): |
64 | | - for pyc_bytes in PYC_BYTES: |
65 | | - marshal.loads(pyc_bytes) |
| 51 | + pyc_bytes = PYC_BYTES |
| 52 | + while inner_iterations > 0: |
| 53 | + marshal.loads(pyc_bytes) |
| 54 | + inner_iterations -= 1 |
66 | 55 |
|
67 | 56 |
|
68 | 57 | def __benchmark__(inner_iterations=1): |
|
0 commit comments