From f83fb4a252b4eeef1c8b5696e2d604a946385e82 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 18 Aug 2022 12:48:08 -0400 Subject: Clean up Python scripts --- scripts/benchmark.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'scripts/benchmark.py') 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 +# Copyright 2011-2022 David Robillard # 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") -- cgit v1.2.1