feat: add benchmark for Wren C API foreign method calls and refactor test class names
Add a new benchmark that measures the performance of calling foreign methods through the Wren C embedding API, specifically testing argument passing and return values with a tight loop of 10 million calls. Refactor test API classes from generic "Api" to specific names like "Call", "Returns", "Value", and "ForeignClass" to avoid naming conflicts with the new benchmark module. Update the benchmark runner to use the test_api executable for API-specific benchmarks and remove the special API test argument handling from the test runner.
This commit is contained in:
+14
-1
@@ -51,6 +51,8 @@ def BENCHMARK(name, pattern):
|
||||
regex = re.compile(pattern + "\n" + r"elapsed: (\d+\.\d+)", re.MULTILINE)
|
||||
BENCHMARKS.append([name, regex, None])
|
||||
|
||||
BENCHMARK("api_foreign_method", "100000000")
|
||||
|
||||
BENCHMARK("binary_trees", """stretch tree of depth 13 check: -1
|
||||
8192 trees of depth 4 check: -8192
|
||||
2048 trees of depth 6 check: -2048
|
||||
@@ -143,9 +145,20 @@ def standard_deviation(times):
|
||||
|
||||
def run_trial(benchmark, language):
|
||||
"""Runs one benchmark one time for one language."""
|
||||
executable_args = language[1]
|
||||
|
||||
# Hackish. If the benchmark name starts with "api_", it's testing the Wren
|
||||
# C API, so run the test_api executable which has those test methods instead
|
||||
# of the normal Wren build.
|
||||
if benchmark[0].startswith("api_"):
|
||||
executable_args = [
|
||||
os.path.join(WREN_DIR, "build", "release", "test", "wren")
|
||||
]
|
||||
|
||||
args = []
|
||||
args.extend(language[1])
|
||||
args.extend(executable_args)
|
||||
args.append(os.path.join(BENCHMARK_DIR, benchmark[0] + language[2]))
|
||||
|
||||
try:
|
||||
out = subprocess.check_output(args, universal_newlines=True)
|
||||
except OSError:
|
||||
|
||||
@@ -111,10 +111,6 @@ class Test:
|
||||
def run(self, app, type):
|
||||
# Invoke wren and run the test.
|
||||
test_arg = self.path
|
||||
if type == "api test":
|
||||
# Just pass the suite name to API tests.
|
||||
test_arg = basename(splitext(test_arg)[0])
|
||||
|
||||
proc = Popen([app, test_arg], stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
||||
|
||||
# If a test takes longer than two seconds, kill it.
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
29729F321BA70A620099CA20 /* io.c in Sources */ = {isa = PBXBuildFile; fileRef = 29729F2E1BA70A620099CA20 /* io.c */; };
|
||||
29729F331BA70A620099CA20 /* io.wren.inc in Sources */ = {isa = PBXBuildFile; fileRef = 29729F301BA70A620099CA20 /* io.wren.inc */; };
|
||||
2986F6D71ACF93BA00BCE26C /* wren_primitive.c in Sources */ = {isa = PBXBuildFile; fileRef = 2986F6D51ACF93BA00BCE26C /* wren_primitive.c */; };
|
||||
29932D511C20D8C900099DEE /* benchmark.c in Sources */ = {isa = PBXBuildFile; fileRef = 29932D4F1C20D8C900099DEE /* benchmark.c */; };
|
||||
29A427341BDBE435001E6E22 /* wren_opt_meta.c in Sources */ = {isa = PBXBuildFile; fileRef = 29A4272E1BDBE435001E6E22 /* wren_opt_meta.c */; };
|
||||
29A427351BDBE435001E6E22 /* wren_opt_meta.c in Sources */ = {isa = PBXBuildFile; fileRef = 29A4272E1BDBE435001E6E22 /* wren_opt_meta.c */; };
|
||||
29A427361BDBE435001E6E22 /* wren_opt_meta.wren.inc in Sources */ = {isa = PBXBuildFile; fileRef = 29A427301BDBE435001E6E22 /* wren_opt_meta.wren.inc */; };
|
||||
@@ -103,6 +104,8 @@
|
||||
29729F301BA70A620099CA20 /* io.wren.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = io.wren.inc; path = ../../src/module/io.wren.inc; sourceTree = "<group>"; };
|
||||
2986F6D51ACF93BA00BCE26C /* wren_primitive.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wren_primitive.c; path = ../../src/vm/wren_primitive.c; sourceTree = "<group>"; };
|
||||
2986F6D61ACF93BA00BCE26C /* wren_primitive.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = wren_primitive.h; path = ../../src/vm/wren_primitive.h; sourceTree = "<group>"; };
|
||||
29932D4F1C20D8C900099DEE /* benchmark.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = benchmark.c; path = ../../test/api/benchmark.c; sourceTree = "<group>"; };
|
||||
29932D501C20D8C900099DEE /* benchmark.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = benchmark.h; path = ../../test/api/benchmark.h; sourceTree = "<group>"; };
|
||||
29A4272E1BDBE435001E6E22 /* wren_opt_meta.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wren_opt_meta.c; path = ../../src/optional/wren_opt_meta.c; sourceTree = "<group>"; };
|
||||
29A4272F1BDBE435001E6E22 /* wren_opt_meta.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = wren_opt_meta.h; path = ../../src/optional/wren_opt_meta.h; sourceTree = "<group>"; };
|
||||
29A427301BDBE435001E6E22 /* wren_opt_meta.wren.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = wren_opt_meta.wren.inc; path = ../../src/optional/wren_opt_meta.wren.inc; sourceTree = "<group>"; };
|
||||
@@ -239,6 +242,8 @@
|
||||
29D0099A1B7E394F000CE58C /* api_test */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
29932D4F1C20D8C900099DEE /* benchmark.c */,
|
||||
29932D501C20D8C900099DEE /* benchmark.h */,
|
||||
29D009A61B7E3993000CE58C /* main.c */,
|
||||
293D46941BB43F9900200083 /* call.c */,
|
||||
293D46951BB43F9900200083 /* call.h */,
|
||||
@@ -356,6 +361,7 @@
|
||||
291647C81BA5EC5E006142EE /* modules.c in Sources */,
|
||||
29DC14A11BBA2FEC008A8274 /* scheduler.c in Sources */,
|
||||
29A427391BDBE435001E6E22 /* wren_opt_random.c in Sources */,
|
||||
29932D511C20D8C900099DEE /* benchmark.c in Sources */,
|
||||
29DC14A01BBA2FD6008A8274 /* timer.c in Sources */,
|
||||
29DC149F1BBA2FCC008A8274 /* vm.c in Sources */,
|
||||
29DC14A21BBA300A008A8274 /* wren_compiler.c in Sources */,
|
||||
|
||||
Reference in New Issue
Block a user