Skip to content

Commit 1642d45

Browse files
committed
Updates to maintainability. Divide by language
1 parent 33d6b02 commit 1642d45

File tree

3 files changed

+49
-26
lines changed

3 files changed

+49
-26
lines changed

benchmarks/maintainability/config.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ modeling_interfaces:
2727
- "lib"
2828
- "src"
2929
exclude_paths:
30-
- "third_party"
30+
- "third_party"
31+
pulp:
32+
github: coin-or/pulp
33+
include_paths: ["pulp"]
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
modeling_interface,blank,comment,code,nFiles
2-
pyomo_core,7985,15195,28753,111
3-
cvxpy,9826,19822,28606,366
4-
pyoptinterface,3282,1316,23319,73
5-
jump,4792,9264,12258,41
6-
linopy,2429,3771,8088,20
7-
pyoframe,760,1979,2614,10
1+
modeling_interface,Python,C++,Julia,total,factor
2+
pyoframe,2614,,,2614,1.0
3+
pulp,7793,,,7793,3.0
4+
linopy,8088,,,8088,3.1
5+
jump,,,12258,12258,4.7
6+
pyoptinterface,5338,17981,,23319,8.9
7+
cvxpy,27306,1300,,28606,10.9
8+
pyomo_core,28753,,,28753,11.0

benchmarks/maintainability/run.py

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def measure_lines_of_code(
4242
exclude_paths: list[str],
4343
exclude_dirs: list[str],
4444
include_exts: list[str],
45-
) -> dict[str, int]:
45+
) -> pl.DataFrame:
4646
if not downloads_dir.exists() or not any(downloads_dir.iterdir()):
4747
url = "https://github.com/" + github
4848
subprocess.run(["git", "clone", url, downloads_dir], check=True)
@@ -72,7 +72,13 @@ def measure_lines_of_code(
7272
raise RuntimeError(
7373
f"Failed to parse cloc output as JSON: {result.stdout}"
7474
) from e
75-
return cloc_output["SUM"]
75+
76+
df = pl.DataFrame(cloc_output)
77+
df = df.select(
78+
pl.col(c).struct.field("code").alias(c) for c in df.columns if c != "header"
79+
)
80+
81+
return df
7682

7783

7884
def main():
@@ -87,29 +93,42 @@ def main():
8793
always_exclude_dirs = config["always_exclude_dirs"]
8894
valid_extensions = config["valid_extensions"]
8995

90-
results = {}
96+
results = pl.DataFrame()
9197

9298
for modeling_interface, mi_config in config["modeling_interfaces"].items():
93-
results[modeling_interface] = measure_lines_of_code(
94-
mi_config["github"],
95-
cwd / "downloads" / modeling_interface,
96-
include_paths=mi_config["include_paths"],
97-
exclude_paths=mi_config.get("exclude_paths", []),
98-
include_exts=valid_extensions,
99-
exclude_dirs=always_exclude_dirs,
99+
results = pl.concat(
100+
[
101+
results,
102+
measure_lines_of_code(
103+
mi_config["github"],
104+
cwd / "downloads" / modeling_interface,
105+
include_paths=mi_config["include_paths"],
106+
exclude_paths=mi_config.get("exclude_paths", []),
107+
include_exts=valid_extensions,
108+
exclude_dirs=always_exclude_dirs,
109+
).with_columns(modeling_interface=pl.lit(modeling_interface)),
110+
],
111+
how="diagonal",
100112
)
101113

102-
results = pl.DataFrame(results, orient="row")
103-
results = results.unpivot(
104-
on=results.columns, variable_name="modeling_interface", value_name="data"
105-
)
106-
results = results.select("modeling_interface", pl.col("data").struct.unnest()).sort(
107-
"code", descending=True
114+
# reorder columns
115+
results = results.with_columns(
116+
(pl.col("C++") + pl.col("C/C++ Header")).alias("C++")
117+
).drop("C/C++ Header")
118+
results = results.select(
119+
"modeling_interface",
120+
*[col for col in results.columns if col not in ("modeling_interface", "SUM")],
121+
total="SUM",
122+
).sort("total")
123+
results = results.with_columns(
124+
factor=(
125+
pl.col("total")
126+
/ results.filter(modeling_interface="pyoframe")["total"].item()
127+
).round(1)
108128
)
109129

110-
results.write_csv(cwd / "results.csv")
111-
112130
print(results)
131+
results.write_csv(cwd / "results.csv")
113132

114133

115134
if __name__ == "__main__":

0 commit comments

Comments
 (0)