Skip to content

Commit 0267c15

Browse files
author
Andrija Kolic
committed
[GR-71293] Port 13 C-extension-module Python interpreter micro benchmarks to PolyBench
PullRequest: graalpython/4129
2 parents 318bc7a + 8f38e58 commit 0267c15

18 files changed

+555
-19
lines changed

graalpython/com.oracle.graal.python.benchmarks/python/harness.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ def ccompile(name, code):
209209

210210
rootdir = os.path.dirname(__file__)
211211
while os.path.basename(rootdir) != 'graalpython':
212+
prevdir = rootdir
212213
rootdir = os.path.dirname(rootdir)
214+
if rootdir == prevdir:
215+
# Reached the root of the file system
216+
raise RuntimeError("'graalpython' directory not found in path!")
213217

214218
sys.path.append(os.path.join(
215219
rootdir,

graalpython/com.oracle.graal.python.benchmarks/python/micro/c-arith-binop.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, 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
@@ -102,6 +102,12 @@
102102
"""
103103

104104

105+
import sys
106+
import os
107+
# Add benchmark directory to path to allow import of harness.py
108+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
109+
from harness import ccompile
110+
105111
ccompile("c_arith_binop_module", code)
106112
from c_arith_binop_module import FloatSubclass
107113

@@ -127,3 +133,28 @@ def measure(num):
127133

128134
def __benchmark__(num=5):
129135
return measure(num)
136+
137+
138+
def run():
139+
__benchmark__(num=2)
140+
141+
142+
def warmupIterations():
143+
return 25
144+
145+
146+
def iterations():
147+
return 30
148+
149+
150+
def summary():
151+
return {
152+
"name": "OutlierRemovalAverageSummary",
153+
"lower-threshold": 0.0,
154+
"upper-threshold": 0.7,
155+
}
156+
157+
158+
def dependencies():
159+
# Required to run `ccompile`
160+
return ["harness.py", "tests/__init__.py"]

graalpython/com.oracle.graal.python.benchmarks/python/micro/c-arith-binop2.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, 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
@@ -191,6 +191,12 @@
191191
"""
192192

193193

194+
import sys
195+
import os
196+
# Add benchmark directory to path to allow import of harness.py
197+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
198+
from harness import ccompile
199+
194200
ccompile("c_arith_binop_module", code)
195201
from c_arith_binop_module import FloatSubclass
196202

@@ -207,12 +213,37 @@ def docompute(num):
207213
return sum_, type(sum_)
208214

209215

210-
def measure(num):
216+
def measure(num, compute_num):
211217
sum_ = 0
212218
for run in range(num):
213-
sum_ += docompute(100)[0]
219+
sum_ += docompute(compute_num)[0]
214220
return sum_
215221

216222

217-
def __benchmark__(num=5):
218-
return measure(num)
223+
def __benchmark__(num=5, compute_num=100):
224+
return measure(num, compute_num)
225+
226+
227+
def run():
228+
__benchmark__(num=1, compute_num=70)
229+
230+
231+
def warmupIterations():
232+
return 60
233+
234+
235+
def iterations():
236+
return 15
237+
238+
239+
def summary():
240+
return {
241+
"name": "OutlierRemovalAverageSummary",
242+
"lower-threshold": 0.0,
243+
"upper-threshold": 0.4,
244+
}
245+
246+
247+
def dependencies():
248+
# Required to run `ccompile`
249+
return ["harness.py", "tests/__init__.py"]

graalpython/com.oracle.graal.python.benchmarks/python/micro/c-call-classmethod.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, 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
@@ -125,6 +125,12 @@
125125
"""
126126

127127

128+
import sys
129+
import os
130+
# Add benchmark directory to path to allow import of harness.py
131+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
132+
from harness import ccompile
133+
128134
ccompile("c_classmethod", code)
129135
from c_classmethod import NativeCustomType
130136

@@ -143,3 +149,28 @@ def measure(num):
143149

144150
def __benchmark__(num=1000000):
145151
return measure(num)
152+
153+
154+
def run():
155+
__benchmark__(num=10000)
156+
157+
158+
def warmupIterations():
159+
return 50
160+
161+
162+
def iterations():
163+
return 40
164+
165+
166+
def summary():
167+
return {
168+
"name": "OutlierRemovalAverageSummary",
169+
"lower-threshold": 0.0,
170+
"upper-threshold": 0.4,
171+
}
172+
173+
174+
def dependencies():
175+
# Required to run `ccompile`
176+
return ["harness.py", "tests/__init__.py"]

graalpython/com.oracle.graal.python.benchmarks/python/micro/c-call-method-int-float.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
"""
6666

6767

68+
import sys
69+
import os
70+
# Add benchmark directory to path to allow import of harness.py
71+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
72+
from harness import ccompile
73+
6874
ccompile("c_min_method_module", code)
6975
from c_min_method_module import as_double
7076

@@ -83,3 +89,28 @@ def measure(num):
8389

8490
def __benchmark__(num=1000000):
8591
return measure(num)
92+
93+
94+
def run():
95+
__benchmark__(num=40000)
96+
97+
98+
def warmupIterations():
99+
return 25
100+
101+
102+
def iterations():
103+
return 35
104+
105+
106+
def summary():
107+
return {
108+
"name": "OutlierRemovalAverageSummary",
109+
"lower-threshold": 0.0,
110+
"upper-threshold": 0.5,
111+
}
112+
113+
114+
def dependencies():
115+
# Required to run `ccompile`
116+
return ["harness.py", "tests/__init__.py"]

graalpython/com.oracle.graal.python.benchmarks/python/micro/c-call-method.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@
141141
"""
142142

143143

144+
import sys
145+
import os
146+
# Add benchmark directory to path to allow import of harness.py
147+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
148+
from harness import ccompile
149+
144150
ccompile("c_method_module", code)
145151
from c_method_module import NativeCustomType
146152

@@ -160,3 +166,28 @@ def measure(num):
160166

161167
def __benchmark__(num=1000000):
162168
return measure(num)
169+
170+
171+
def run():
172+
__benchmark__(num=3000)
173+
174+
175+
def warmupIterations():
176+
return 0
177+
178+
179+
def iterations():
180+
return 10
181+
182+
183+
def summary():
184+
return {
185+
"name": "OutlierRemovalAverageSummary",
186+
"lower-threshold": 0.0,
187+
"upper-threshold": 0.7,
188+
}
189+
190+
191+
def dependencies():
192+
# Required to run `ccompile`
193+
return ["harness.py", "tests/__init__.py"]

graalpython/com.oracle.graal.python.benchmarks/python/micro/c-instantiate-large.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, 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
@@ -119,6 +119,12 @@
119119
"""
120120

121121

122+
import sys
123+
import os
124+
# Add benchmark directory to path to allow import of harness.py
125+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
126+
from harness import ccompile
127+
122128
ccompile("c_instantiation", code)
123129
import c_instantiation
124130

@@ -138,3 +144,28 @@ def measure(num):
138144

139145
def __benchmark__(num=1000000):
140146
return measure(num)
147+
148+
149+
def run():
150+
__benchmark__(num=10)
151+
152+
153+
def warmupIterations():
154+
return 0
155+
156+
157+
def iterations():
158+
return 70
159+
160+
161+
def summary():
162+
return {
163+
"name": "OutlierRemovalAverageSummary",
164+
"lower-threshold": 0.1,
165+
"upper-threshold": 0.2,
166+
}
167+
168+
169+
def dependencies():
170+
# Required to run `ccompile`
171+
return ["harness.py", "tests/__init__.py"]

graalpython/com.oracle.graal.python.benchmarks/python/micro/c-issubtype-monorphic.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, 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
@@ -124,6 +124,12 @@
124124
"""
125125

126126

127+
import sys
128+
import os
129+
# Add benchmark directory to path to allow import of harness.py
130+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
131+
from harness import ccompile
132+
127133
ccompile("c_classmethod", code)
128134
from c_classmethod import NativeCustomType
129135

@@ -142,3 +148,28 @@ def measure(num):
142148

143149
def __benchmark__(num=1000000):
144150
return measure(num)
151+
152+
153+
def run():
154+
__benchmark__(num=10000)
155+
156+
157+
def warmupIterations():
158+
return 10
159+
160+
161+
def iterations():
162+
return 20
163+
164+
165+
def summary():
166+
return {
167+
"name": "OutlierRemovalAverageSummary",
168+
"lower-threshold": 0.1,
169+
"upper-threshold": 0.4,
170+
}
171+
172+
173+
def dependencies():
174+
# Required to run `ccompile`
175+
return ["harness.py", "tests/__init__.py"]

graalpython/com.oracle.graal.python.benchmarks/python/micro/c-issubtype-polymorphic-forced-to-native.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, 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
@@ -128,6 +128,12 @@
128128
"""
129129

130130

131+
import sys
132+
import os
133+
# Add benchmark directory to path to allow import of harness.py
134+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
135+
from harness import ccompile
136+
131137
ccompile("c_classmethod", code)
132138
from c_classmethod import NativeCustomType
133139

@@ -147,3 +153,28 @@ def measure(num):
147153

148154
def __benchmark__(num=1000000):
149155
return measure(num)
156+
157+
158+
def run():
159+
__benchmark__(num=10000)
160+
161+
162+
def warmupIterations():
163+
return 0
164+
165+
166+
def iterations():
167+
return 30
168+
169+
170+
def summary():
171+
return {
172+
"name": "OutlierRemovalAverageSummary",
173+
"lower-threshold": 0.1,
174+
"upper-threshold": 0.4,
175+
}
176+
177+
178+
def dependencies():
179+
# Required to run `ccompile`
180+
return ["harness.py", "tests/__init__.py"]

0 commit comments

Comments
 (0)