Skip to content

Commit 3aea3a0

Browse files
authored
Merge pull request #71867 from oscbyspro/better-create-benchmark-script
Some create_benchmark.py script enhancements.
2 parents a983de3 + bd2abc6 commit 3aea3a0

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

benchmark/scripts/Template.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//===--- {name}.swift -------------------------------------------===//
1+
//===--- {name}.swift {padding}---===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) {year} Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -12,7 +12,7 @@
1212

1313
import TestsUtils
1414

15-
public let {name} = [
15+
public let benchmarks = [
1616
BenchmarkInfo(name: "{name}", runFunction: run_{name}, tags: [.validation, .api]),
1717
]
1818

benchmark/scripts/create_benchmark.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import argparse
4+
import datetime
45
import os
56
import re
67

@@ -46,18 +47,22 @@ def create_benchmark_file(name):
4647
and places it in the `single-source` directory.
4748
"""
4849

50+
file_text = ""
4951
template_path = create_relative_path("Template.swift")
50-
benchmark_template = ""
5152
with open(template_path, "r") as f:
52-
benchmark_template = "".join(f.readlines())
53+
file_text = "".join(f.readlines())
5354

54-
# fill in template with benchmark name.
55-
formatted_template = benchmark_template.format(name=name)
55+
# fill in missing template details
56+
file_text = file_text.format(
57+
name=name,
58+
padding="-" * (56 - len(name)),
59+
year=datetime.date.today().year
60+
)
5661

57-
relative_path = create_relative_path("../single-source/")
58-
source_file_path = os.path.join(relative_path, name + ".swift")
59-
with open(source_file_path, "w") as f:
60-
f.write(formatted_template)
62+
file_path_prefix = create_relative_path("../single-source/")
63+
file_path = os.path.join(file_path_prefix, name + ".swift")
64+
with open(file_path, "w") as f:
65+
f.write(file_text)
6166

6267

6368
def add_import_benchmark(name):
@@ -119,9 +124,9 @@ def add_register_benchmark(name):
119124

120125
file_new_contents = insert_line_alphabetically(
121126
name,
122-
"registerBenchmark(" + name + ")\n",
127+
"register(" + name + ".benchmarks)\n",
123128
file_contents,
124-
r"registerBenchmark\(([a-zA-Z]+)\)",
129+
r"register\(([a-zA-Z]+)\.benchmarks\)",
125130
)
126131
with open(relative_path, "w") as f:
127132
for line in file_new_contents:

0 commit comments

Comments
 (0)