-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_runtime.py
88 lines (72 loc) · 2.98 KB
/
plot_runtime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import argparse
import timeit
from pathlib import Path
import pandas as pd
import plotly.express as px
from astdiff.context import DiffContext
from astdiff.generator.with_move import WithMoveEditScriptGenerator
from astdiff.matcher.gumtree import GumTreeMatcher
from astdiff.parser.base import ParseOptions
from astdiff.parser.builtin import BuiltInASTParser
argparser = argparse.ArgumentParser()
argparser.add_argument("--export-path")
args = argparser.parse_args()
file_paths = [
(
"tests/data/runtimetest/django_wsgi_200.py",
"tests/data/runtimetest/django_asgi_300.py",
),
(
"tests/data/runtimetest/django_core_validators_600.py",
"tests/data/runtimetest/django_admin_filters_500.py",
),
(
"tests/data/runtimetest/django_get_or_create_tests_700.py",
"tests/data/runtimetest/django_constraints_tests_800.py",
),
(
"tests/data/runtimetest/django_models_options_1000.py",
"tests/data/runtimetest/django_postgres_test_array_1400.py",
),
(
"tests/data/runtimetest/django_aggregation_regress_1800.py",
"tests/data/runtimetest/django_migrations_test_state_2000.py",
),
(
"tests/data/runtimetest/django_migrations_test_state_2000.py",
"tests/data/runtimetest/django_model_fields_init_2700.py",
),
]
def plot():
parser = BuiltInASTParser(ParseOptions(True, True))
matcher = GumTreeMatcher()
generator = WithMoveEditScriptGenerator()
times = []
for source_path, target_path in file_paths:
print(f"Comparing {source_path} and {target_path}...")
source_code = Path(source_path).read_text()
target_code = Path(target_path).read_text()
start_time = timeit.default_timer()
source_ast = parser.parse_code(source_code)
target_ast = parser.parse_code(target_code)
context = DiffContext(source_ast, target_ast)
end_time = timeit.default_timer()
input_size = max(source_ast.metadata.size, target_ast.metadata.size)
times.append((input_size, "parsing", end_time - start_time))
matcher.prepare(context)
start_time = timeit.default_timer()
matcher.match_anchors(context.source_root, context.target_root)
end_time = timeit.default_timer()
times.append((input_size, "anchor matching", end_time - start_time))
start_time = timeit.default_timer()
matcher.match_containers(context.source_root, context.target_root)
end_time = timeit.default_timer()
times.append((input_size, "container matching", end_time - start_time))
start_time = timeit.default_timer()
context.edit_script = generator.generate_edit_script(context)
end_time = timeit.default_timer()
times.append((input_size, "script generation", end_time - start_time))
df = pd.DataFrame(times, columns=["input size", "phase", "time"])
fig = px.line(df, x="input size", y="time", color="phase")
fig.write_image(args.export_path)
print("Done!")