Skip to content

Commit 9950e04

Browse files
authored
Merge branch 'main' into feature/UpdateDuckdb
2 parents 44c8ca1 + 6bf29d6 commit 9950e04

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

run_benchmark_simple.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def clean_page_cache():
99
Clean the system page cache using the sync command and writing to /proc/sys/vm/drop_caches
1010
Requires root privileges (sudo) to execute successfully
1111
"""
12+
1213
cmd = "sudo bash -c \"sync; echo 3 > /proc/sys/vm/drop_caches\""
1314
if verbose:
1415
print(cmd)
@@ -23,25 +24,31 @@ def run_benchmark(benchmark_path, draw=0):
2324
draw (int): Flag to enable result plotting (1 = enable, 0 = disable)
2425
"""
2526
# Verify the provided path is a valid directory
27+
2628
if not os.path.isdir(benchmark_path):
27-
print(f"Error: {benchmark_path} is not a valid directory")
29+
print(f"错误: {benchmark_path} 不是一个有效的目录")
2830
return
2931

32+
3033
# Get last two parts of the path to use as output filename
34+
3135
path_parts = os.path.normpath(benchmark_path).split(os.sep)
3236
output_name = f"{path_parts[-2]}_{path_parts[-1]}"
3337
output_csv = "output/"+f"{output_name}.csv"
3438

3539
results = []
3640

41+
3742
# Traverse through all files in the directory
3843
for root, dirs, files in os.walk(benchmark_path):
3944
# Sort files ending with .benchmark by numeric part in filename
45+
4046
files = sorted([file for file in files if file.endswith('.benchmark')],
4147
key=lambda x: int(x[1:3]))
4248
print(files)
4349
for file in files:
4450
if file.endswith('.benchmark'):
51+
4552
# Construct full file path
4653
benchmark_file = os.path.join(root, file)
4754

@@ -53,14 +60,17 @@ def run_benchmark(benchmark_path, draw=0):
5360
print(cmd)
5461
output = subprocess.getoutput(cmd)
5562

63+
5664
# Collect all run results
65+
5766
run_times = []
5867
print(output)
5968
for line in output.splitlines():
6069
if line.startswith('Result:'):
6170
time = float(line.split()[1])
6271
run_times.append(time)
6372
if verbose:
73+
6474
print(f"File {file} runtime: {time}")
6575

6676
# Save all run times if results exist
@@ -72,8 +82,10 @@ def run_benchmark(benchmark_path, draw=0):
7282
else:
7383
if verbose:
7484
print(f"No results found for file {file}")
85+
7586
except Exception as e:
76-
print(f"Error running {benchmark_file}: {e}")
87+
print(f"运行 {benchmark_file} 时出错: {e}")
88+
7789

7890
# Save results to CSV file
7991
with open(output_csv, 'w', newline='') as csvfile:
@@ -86,16 +98,20 @@ def run_benchmark(benchmark_path, draw=0):
8698
# Write all run results for each benchmark
8799
for file, times in results:
88100
# Ensure consistent column count per row
101+
89102
row = [file] + times + [''] * (max_runs - len(times))
90103
writer.writerow(row)
91104

92-
print(f"Results saved to {output_csv}")
105+
print(f"结果已保存到 {output_csv}")
106+
93107

94108
# Generate plot if requested
109+
95110
if draw:
96111
plot_results(output_name, results)
97112

98113
def plot_results(title, results):
114+
99115
"""
100116
Generate a bar chart from benchmark results showing average run times
101117
@@ -118,14 +134,17 @@ def plot_results(title, results):
118134
plt.tight_layout()
119135
plt.savefig("output/"+f"{title}.png")
120136
plt.show()
137+
121138
print(f"Chart saved as {title}.png")
122139

140+
123141
if __name__ == "__main__":
124142
# Global variables for configuration
125143
global pixels_home
126144
global verbose
127145
global nRuns
128146

147+
129148
# Get PIXELS_SRC environment variable
130149
pixels_home = os.environ.get('PIXELS_SRC')
131150
current_dir = os.getcwd()
@@ -151,8 +170,11 @@ def plot_results(title, results):
151170

152171

153172
# Clean page cache if not reading from cache
173+
154174
if not from_page_cache:
155175
clean_page_cache()
156176

157177
# Run benchmarks with provided arguments
158178
run_benchmark(args.dir, args.draw)
179+
180+

0 commit comments

Comments
 (0)