-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45c598c
commit 2626cb6
Showing
4 changed files
with
121 additions
and
189 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
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,26 @@ | ||
import os | ||
import math | ||
import random | ||
from typing import List | ||
from lexems import KEYWODRS, OPERATORS, INDETIFICATORS, LITERALS | ||
|
||
def simple_lexems_generator(words_count: int, words_multiplier: int, output_folder: str) -> List[str]: | ||
|
||
lexems = {**OPERATORS, **KEYWODRS, **INDETIFICATORS, **LITERALS} | ||
|
||
lexems_keys = list(lexems.keys()) | ||
|
||
words_counts = [int(math.pow(words_multiplier, i)) for i in range(0, len(str(words_count)))] | ||
tests_paths = [] | ||
for value in words_counts: | ||
generated_file_path = os.path.join(output_folder, f"{value}.py") | ||
validation_file_path = os.path.join(output_folder, f"validation_{value}.val") | ||
tests_paths.append(generated_file_path) | ||
with open(generated_file_path, "w"), open(validation_file_path, "w") as (generated_file, validation_file): | ||
for i in range(value): | ||
random_lexem = lexems_keys[random.randint(0, len(lexems) - 1)] | ||
generated_file.writelines(lexems[random_lexem] + ' ') | ||
validation_file.writelines(lexems[random_lexem] + '\n') | ||
|
||
|
||
return tests_paths |
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,62 @@ | ||
from argparse import ArgumentParser | ||
import random | ||
import os | ||
import tokenize | ||
import time | ||
import subprocess | ||
from enum import Enum | ||
import math | ||
import json | ||
import pandas | ||
from generators import lexer_generator | ||
|
||
CLI_PATH = "../compiler/build/bin/Release/compiler.exe" | ||
|
||
|
||
def parse_args(): | ||
|
||
parser = ArgumentParser() | ||
parser.add_argument('--max-word-count', type=int, help="Maximum words in test file", default=1000000) | ||
parser.add_argument('--words-multiplier', type=int, help="Step for files", default=10) | ||
parser.add_argument('-o', '--output', type=str,help="Output folder", default="results") | ||
# add generate argument | ||
|
||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = parse_args() | ||
os.makedirs(args.output, exist_ok=True) | ||
test_files_folder = os.path.join(args.output, "test_files") | ||
os.makedirs(test_files_folder, exist_ok=True) | ||
compiler_logs = os.path.join(args.output, "compiler_logs") | ||
os.makedirs(compiler_logs, exist_ok=True) | ||
|
||
tests_paths = lexer_generator(args.words_count, args.words_multiplier, test_files_folder) | ||
|
||
tokenize_times = {} | ||
output = {} | ||
for filename in tests_paths: | ||
with open(filename, 'rb') as test_file: | ||
start = time.perf_counter() | ||
x = list(tokenize.tokenize(test_file.__next__)) | ||
end = time.perf_counter() | ||
tokenize_times[int(os.path.basename(filename)[:-3])] = float(end - start) | ||
|
||
print(tokenize_times) | ||
|
||
data_frame = pandas.DataFrame.from_dict(tokenize_times, orient='index') | ||
data_frame.to_csv( | ||
os.path.join(args.output, "tokenize_times.csv") | ||
) | ||
|
||
c_times = {} # parse c++ logs | ||
for filename in tests_paths: | ||
subprocess.run( | ||
CLI_PATH + | ||
f" -l {os.path.join(compiler_logs, os.path.basename(filename)[:-3])}.txt -v -O --last-module lexer --times " + | ||
filename | ||
) | ||
|
||
|
||
main() |
This file was deleted.
Oops, something went wrong.