diff options
Diffstat (limited to 'scripts/benchmark.py')
-rwxr-xr-x | scripts/benchmark.py | 14 |
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") |