|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 |
|
3 | 3 | import argparse
|
| 4 | +import datetime |
4 | 5 | import os
|
5 | 6 | import re
|
6 | 7 |
|
@@ -47,17 +48,22 @@ def create_benchmark_file(name):
|
47 | 48 | """
|
48 | 49 |
|
49 | 50 | template_path = create_relative_path("Template.swift")
|
50 |
| - benchmark_template = "" |
| 51 | + file_text = "" |
| 52 | + |
51 | 53 | with open(template_path, "r") as f:
|
52 |
| - benchmark_template = "".join(f.readlines()) |
| 54 | + file_text = "".join(f.readlines()) |
53 | 55 |
|
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) |
61 | 67 |
|
62 | 68 |
|
63 | 69 | def add_import_benchmark(name):
|
@@ -119,9 +125,9 @@ def add_register_benchmark(name):
|
119 | 125 |
|
120 | 126 | file_new_contents = insert_line_alphabetically(
|
121 | 127 | name,
|
122 |
| - "registerBenchmark(" + name + ")\n", |
| 128 | + "register(" + name + ".benchmarks)\n", |
123 | 129 | file_contents,
|
124 |
| - r"registerBenchmark\(([a-zA-Z]+)\)", |
| 130 | + r"register\(([a-zA-Z]+)\.benchmarks\)", |
125 | 131 | )
|
126 | 132 | with open(relative_path, "w") as f:
|
127 | 133 | for line in file_new_contents:
|
|
0 commit comments