diff options
author | David Robillard <d@drobilla.net> | 2021-09-10 20:11:42 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-09-10 20:54:28 -0400 |
commit | 497b0a9fb716023b73bb5fc1c8c451da11ba32d8 (patch) | |
tree | 8b03887204bf209de501efae461d63c85b0d4c0e | |
parent | 0f06d8ae30119e10ffb2b7b5ec5e6b51c624cd1d (diff) | |
download | zix-497b0a9fb716023b73bb5fc1c8c451da11ba32d8.tar.gz zix-497b0a9fb716023b73bb5fc1c8c451da11ba32d8.tar.bz2 zix-497b0a9fb716023b73bb5fc1c8c451da11ba32d8.zip |
Generate slightly more realistic hash benchmark data
-rwxr-xr-x | scripts/benchmark.py | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/scripts/benchmark.py b/scripts/benchmark.py index aec2bf5..5ea1d9f 100755 --- a/scripts/benchmark.py +++ b/scripts/benchmark.py @@ -26,18 +26,29 @@ subprocess.call( # Benchmark dictionaries FILENAME = "gibberish.txt" -CHARACTERS = string.ascii_letters + string.digits +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"] def random_word(): """Return a random word with ASCII letters and digits""" - wordlen = random.randrange(1, 64) - word = "" - for _ in range(wordlen): - word += random.choice(CHARACTERS) + if random.randint(0, 1): + # Generate a URI + result = "%s://%s/" % (random.choice(SCHEMES), random.choice(DOMAINS)) + for _ in range(random.randrange(1, 6)): + result += random.choice(NAMES) + "/" + else: + result = "" + for _ in range(random.randrange(1, 7)): + result += random.choice(WORDS).strip() + " " - return word + result += random.choice(WORDS).strip() + + return result if not os.path.exists(FILENAME): @@ -45,7 +56,8 @@ if not os.path.exists(FILENAME): with open(FILENAME, "w") as out: for i in range(1 << 20): - out.write(random_word() + "\n") + out.write(random_word()) + out.write("\n") subprocess.call(["./dict_bench", "gibberish.txt"]) subprocess.call( |