|
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 |
|
@@ -46,18 +47,22 @@ def create_benchmark_file(name): |
46 | 47 | and places it in the `single-source` directory. |
47 | 48 | """ |
48 | 49 |
|
| 50 | + file_text = "" |
49 | 51 | template_path = create_relative_path("Template.swift") |
50 | | - benchmark_template = "" |
51 | 52 | with open(template_path, "r") as f: |
52 | | - benchmark_template = "".join(f.readlines()) |
| 53 | + file_text = "".join(f.readlines()) |
53 | 54 |
|
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 | + ) |
56 | 61 |
|
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) |
61 | 66 |
|
62 | 67 |
|
63 | 68 | def add_import_benchmark(name): |
@@ -119,9 +124,9 @@ def add_register_benchmark(name): |
119 | 124 |
|
120 | 125 | file_new_contents = insert_line_alphabetically( |
121 | 126 | name, |
122 | | - "registerBenchmark(" + name + ")\n", |
| 127 | + "register(" + name + ".benchmarks)\n", |
123 | 128 | file_contents, |
124 | | - r"registerBenchmark\(([a-zA-Z]+)\)", |
| 129 | + r"register\(([a-zA-Z]+)\.benchmarks\)", |
125 | 130 | ) |
126 | 131 | with open(relative_path, "w") as f: |
127 | 132 | for line in file_new_contents: |
|
0 commit comments