Skip to content

Commit a7f0723

Browse files
committed
[GR-70604] Add unmarshal pyc benchmark.
PullRequest: graalpython/4038
2 parents 947c06d + 7d396a1 commit a7f0723

File tree

5 files changed

+572
-45
lines changed

5 files changed

+572
-45
lines changed

graalpython/com.oracle.graal.python.benchmarks/python/micro/unmarshal-pyc.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -43,26 +43,15 @@
4343
import os
4444

4545

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"))
6048

6149

6250
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
6655

6756

6857
def __benchmark__(inner_iterations=1):

0 commit comments

Comments
 (0)