summaryrefslogtreecommitdiffstats
path: root/tools/benchmark
diff options
context:
space:
mode:
authorGangzheng Tong <tonggangzheng@gmail.com>2025-04-11 16:55:29 -0700
committerGitHub <noreply@github.com>2025-04-11 23:55:29 +0000
commit6dd5bd52e3a5fb721776224e5e9a390d626faf26 (patch)
tree1b032d0be5a3756dffc1b55d461ed8128b328102 /tools/benchmark
parent8e6af6259bd1dd47d81c36f0562ff362ca5d42c3 (diff)
Fix benchmark/compile.py nested f-string and deprecated constant issues (#6773)
This commit resolves three issues in the benchmark script: 1. Fixed nested f-string syntax error that was causing CI failures (fixes #6772) 2. Fixed key access error handling for timing dictionary The nested f-string was causing a syntax error in CI, and the proper fix is to create the key variable separately before using it. Also improved error handling for cases where compilation fails and timing data might be missing. Fixes: #6772
Diffstat (limited to 'tools/benchmark')
-rw-r--r--tools/benchmark/compile.py57
1 files changed, 38 insertions, 19 deletions
diff --git a/tools/benchmark/compile.py b/tools/benchmark/compile.py
index 534e090bc..b46440529 100644
--- a/tools/benchmark/compile.py
+++ b/tools/benchmark/compile.py
@@ -73,9 +73,9 @@ def run(command, key):
try:
results = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True).decode('utf-8')
except subprocess.CalledProcessError as exc:
+ print(f"[Error] Failed to run command: {command}")
print(exc.output.decode('utf-8'))
- return
- # exit(-1)
+ return # Return without adding to timings
p = parse(results)
if len(profile) == 0:
@@ -85,10 +85,13 @@ def run(command, key):
profile.setdefault(k, 0)
profile[k] += v
- for k in profile:
- profile[k] /= samples
-
- timings[key] = profile
+ # Only add to timings if we have data
+ if profile:
+ for k in profile:
+ profile[k] /= samples
+ timings[key] = profile
+ else:
+ print(f"[Warning] No timing data collected for {key}")
def compile_cmd(file, output, stage=None, entry=None, emit=False):
cmd = f'{slangc} -report-perf-benchmark {file}'
@@ -171,8 +174,8 @@ for k, v in timings.items():
data = {
'name': name,
- 'unit': 'milliseconds',
- 'value': v['compileInner']
+ 'value': v['compileInner'],
+ 'unit': 'milliseconds'
}
json_data.append(data)
@@ -185,7 +188,11 @@ with open(args.output, 'w') as file:
print(4 * '\n')
print('# Slang MDL benchmark results\n')
print('## Module precompilation time\n')
-print(f'Total: **{timings[f'full/{target_ext}/precompilation']['compileInner']} ms**\n')
+precomp_key = f'full/{target_ext}/precompilation'
+if precomp_key in timings:
+ print(f'Total: **{timings[precomp_key]["compileInner"]} ms**\n')
+else:
+ print("No precompilation data available\n")
print('## Module compilation for entry points\n')
@@ -199,11 +206,17 @@ table.field_names = [ 'Entry', 'Total' ]
total = 0
for entry, prefix in zip(entries, prefixes):
row = [ entry ]
- db = timings[f'full/{target_ext}/module/{prefix}']
- spCompile = db['compileInner']
- row.append(f'{spCompile:.3f}s')
- table.add_row(row)
- total += spCompile
+ key = f'full/{target_ext}/module/{prefix}'
+ if key in timings:
+ db = timings[key]
+ spCompile = db.get('compileInner', 0)
+ row.append(f'{spCompile:.3f}ms')
+ table.add_row(row)
+ total += spCompile
+ else:
+ row.append('Failed')
+ table.add_row(row)
+ print(f"[Warning] Compilation failed for module/{prefix}")
print(f'Total: **{total} ms**\n')
print(table, end='\n\n')
@@ -217,11 +230,17 @@ table.field_names = [ 'Entry', 'Total' ]
total = 0
for entry, prefix in zip(entries, prefixes):
row = [ entry ]
- db = timings[f'full/{target_ext}/mono/{prefix}']
- spCompile = db['compileInner']
- row.append(f'{spCompile:.3f}s')
- table.add_row(row)
- total += spCompile
+ key = f'full/{target_ext}/mono/{prefix}'
+ if key in timings:
+ db = timings[key]
+ spCompile = db.get('compileInner', 0)
+ row.append(f'{spCompile:.3f}ms')
+ table.add_row(row)
+ total += spCompile
+ else:
+ row.append('Failed')
+ table.add_row(row)
+ print(f"[Warning] Compilation failed for mono/{prefix}")
print(f'Total: **{total} ms**\n')
print(table, end='\n\n') \ No newline at end of file