-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbenchmark.py
executable file
·71 lines (53 loc) · 2.14 KB
/
benchmark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
import atexit
import subprocess
import sys
import time
from shutil import copytree
from os import path
from pathlib import Path
from shutil import copy2, rmtree
LOCALES = ["en", "fr-FR", "de-DE", "sv", "no", "pl", "br-PT", "it", "ja", "ro", "th", "tr", "uk", "vi"]
BENCHMARK_CONFIG_FILE = "Benchmark/example.config"
# Setup exit handler
@atexit.register
def exit_handler():
rmtree("Benchmark/")
# Create directory if needed
print("Setting up benchmark directory")
Path("Benchmark/").mkdir(parents=True, exist_ok=True)
Path("Benchmark/Strings").mkdir(parents=True, exist_ok=True)
# Replace `Example` with `Benchmark` in config file
with open("Example/example.config", "rt", encoding="utf-8") as fin:
with open(BENCHMARK_CONFIG_FILE, "wt", encoding="utf-8") as fout:
for line in fin:
fout.write(line.replace("Example", "Benchmark"))
# Copy template files
TEMPLATE_FILES_FOLDER = "Example/Template Files/"
copytree(TEMPLATE_FILES_FOLDER, "Benchmark/Template Files/")
# Copying over screenshots and titles
for locale in LOCALES:
print(f"Copying files for {locale}")
for device in ["iPhone X", "iPad Pro"]:
screenshot_source_folder = f"Example/Screenshots/{device}/en"
screenshot_target_folder = f"Benchmark/Screenshots/{device}/{locale}"
copytree(screenshot_source_folder, screenshot_target_folder)
STRING_SOURCE_FILE = "Example/Strings/en.strings"
STRING_DESTINATION_FILE = f"Benchmark/Strings/{locale}.strings"
copy2(STRING_SOURCE_FILE, STRING_DESTINATION_FILE)
# Clear .build directory
if path.exists(".build"):
rmtree(".build")
# Compile SwiftFrame
compile_process = subprocess.run("swift build -c release", shell=True, check=True)
if compile_process.returncode != 0:
sys.exit(compile_process.returncode)
# Running benchmark
benchmark_start = time.time()
run_process = subprocess.run(
".build/release/swiftframe Benchmark/example.config --verbose --output-whole-image", shell=True, check=True
)
benchmark_end = time.time()
if run_process.returncode != 0:
sys.exit(compile_process.returncode)
print(f"Benchmark finished in {benchmark_end - benchmark_start}s")