Skip to content

Commit 5b8ce67

Browse files
committed
Some create_benchmark.py script enhancements.
This commit addresses some trials and tribulations I encountered while working on (#71786). It: 1. fixes the auto-registration regex 2. fixes the auto-generated array's name 3. generates the current year for the license header 4. generates some dashes for the license header
1 parent 0b37768 commit 5b8ce67

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
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: 17 additions & 11 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

@@ -47,17 +48,22 @@ def create_benchmark_file(name):
4748
"""
4849

4950
template_path = create_relative_path("Template.swift")
50-
benchmark_template = ""
51+
file_text = ""
52+
5153
with open(template_path, "r") as f:
52-
benchmark_template = "".join(f.readlines())
54+
file_text = "".join(f.readlines())
5355

54-
# fill in template with benchmark name.
55-
formatted_template = benchmark_template.format(name=name)
56-
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)
56+
# fill in missing template details
57+
file_text = file_text.format(
58+
name = name,
59+
padding = "-" * (55 - len(name)),
60+
year = datetime.date.today().year
61+
)
62+
63+
file_path_prefix = create_relative_path("../single-source/")
64+
file_path = os.path.join(file_path_prefix, name + ".swift")
65+
with open(file_path, "w") as f:
66+
f.write(file_text)
6167

6268

6369
def add_import_benchmark(name):
@@ -119,9 +125,9 @@ def add_register_benchmark(name):
119125

120126
file_new_contents = insert_line_alphabetically(
121127
name,
122-
"registerBenchmark(" + name + ")\n",
128+
"register(" + name + ".benchmarks)\n",
123129
file_contents,
124-
r"registerBenchmark\(([a-zA-Z]+)\)",
130+
r"register\(([a-zA-Z]+)\.benchmarks\)",
125131
)
126132
with open(relative_path, "w") as f:
127133
for line in file_new_contents:

0 commit comments

Comments
 (0)