-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test for speed as opposed to accuracy. The new python script ma…
…kes one file with many test cases instead of multiples files, each with one test case.
- Loading branch information
1 parent
3e96d76
commit 51583e6
Showing
3 changed files
with
77 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import random | ||
import os | ||
import subprocess | ||
|
||
|
||
def generate_binary_string(length): | ||
"""Generate a random binary string of given length.""" | ||
return "".join(random.choice("01") for _ in range(length)) | ||
|
||
|
||
def generate_tests(num_tests): | ||
"""Generate `num_tests` random tests.""" | ||
tests = [] | ||
for _ in range(num_tests): | ||
# Generate a random binary string (up to 32 bits for u32 in Rust) | ||
binary_string = generate_binary_string(random.randint(1, 24)) | ||
tests.append((binary_string)) | ||
|
||
return tests | ||
|
||
|
||
def write_input_files(tests, input_dir): | ||
os.makedirs(input_dir, exist_ok=True) | ||
input_paths = [] | ||
|
||
for binary_string in tests: | ||
input_path = os.path.join(input_dir, f"speed_test.in") | ||
with open(input_path, "a") as f: | ||
f.write(f"{binary_string}\n") | ||
input_paths.append(input_path) | ||
|
||
return input_paths | ||
|
||
|
||
if __name__ == "__main__": | ||
num_tests = 1_000_000 | ||
input_dir = "./testsuite/inputs" | ||
exponent = -4 | ||
|
||
# Generate Tests | ||
tests = generate_tests(num_tests) | ||
|
||
# Write Input File | ||
write_input_files(tests, input_dir) | ||
|
||
print(f"Input files are located in {input_dir}.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters