summaryrefslogtreecommitdiffstats
path: root/scripts/benchmark.py
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-08-18 12:48:08 -0400
committerDavid Robillard <d@drobilla.net>2022-08-18 12:48:08 -0400
commitf83fb4a252b4eeef1c8b5696e2d604a946385e82 (patch)
tree05b5d59ce7ea7649f9aab296008ec62eaa1e7a03 /scripts/benchmark.py
parent5f0dd782d7deca9b34aba578bd5c9f5fb22eb5bd (diff)
downloadzix-f83fb4a252b4eeef1c8b5696e2d604a946385e82.tar.gz
zix-f83fb4a252b4eeef1c8b5696e2d604a946385e82.tar.bz2
zix-f83fb4a252b4eeef1c8b5696e2d604a946385e82.zip
Clean up Python scripts
Diffstat (limited to 'scripts/benchmark.py')
-rwxr-xr-xscripts/benchmark.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/scripts/benchmark.py b/scripts/benchmark.py
index 2249fd1..c160445 100755
--- a/scripts/benchmark.py
+++ b/scripts/benchmark.py
@@ -1,6 +1,6 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
-# Copyright 2011-2021 David Robillard <d@drobilla.net>
+# Copyright 2011-2022 David Robillard <d@drobilla.net>
# SPDX-License-Identifier: ISC
"""
@@ -30,18 +30,20 @@ subprocess.call(
FILENAME = "gibberish.txt"
CHARACTERS = string.ascii_letters + string.digits + " '."
-WORDS = open("/usr/share/dict/words", "r").readlines()
SCHEMES = ["http", "https"]
DOMAINS = ["example.org", "drobilla.net", "lv2plug.in", "gitlab.com"]
NAMES = ["ns", "foo", "bar", "stuff", "things"]
+with open("/usr/share/dict/words", "r", encoding="utf-8") as words_file:
+ WORDS = words_file.readlines()
+
def random_word():
"""Return a random word with ASCII letters and digits"""
if random.randint(0, 1):
# Generate a URI
- result = "%s://%s/" % (random.choice(SCHEMES), random.choice(DOMAINS))
+ result = f"{random.choice(SCHEMES)}://{random.choice(DOMAINS)}/"
for _ in range(random.randrange(1, 6)):
result += random.choice(NAMES) + "/"
else:
@@ -55,9 +57,9 @@ def random_word():
if not os.path.exists(FILENAME):
- print("Generating random text %s" % FILENAME)
+ print(f"Generating random text {FILENAME}")
- with open(FILENAME, "w") as out:
+ with open(FILENAME, "w", encoding="utf-8") as out:
for i in range(1 << 20):
out.write(random_word())
out.write("\n")