Skip to content

Commit e7cd6ac

Browse files
committed
test json size
1 parent db2e067 commit e7cd6ac

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

.github/workflows/jsonsize.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: JSON size opt
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
8+
json:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
13+
- uses: actions/checkout@v2
14+
15+
- run: |
16+
for d in ./libraries/*; do
17+
git submodule update --init "$d"/latest
18+
done
19+
20+
- run: ./jsonsize.py

jsonsize.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
3+
from pathlib import Path
4+
from json import dumps, loads
5+
6+
ROOT = Path(__file__).resolve().parent / 'libraries'
7+
8+
def printSize(key, origSize, dumpSize):
9+
_GB = (1024 * 1024 * 1024)
10+
print(
11+
f'{key}:',
12+
origSize / _GB, 'GB',
13+
'->',
14+
dumpSize / _GB, 'GB',
15+
f"[{100*dumpSize/origSize}%]" if origSize != 0 else ""
16+
)
17+
18+
origSize = {}
19+
dumpSize = {}
20+
21+
# For each library
22+
for _dir in ROOT.iterdir():
23+
_dname = _dir.name
24+
25+
# Check latest version only
26+
_verdir = _dir / 'latest'
27+
28+
# Initialize size counters
29+
origSize[_dname] = 0
30+
dumpSize[_dname] = 0
31+
32+
# For each '*.lib.json' file (recursively)
33+
for item in _verdir.glob('**/*.lib.json'):
34+
# Get and accumulate size
35+
origSize[_dname] += item.stat().st_size
36+
# Read and dump
37+
_dump = Path(str(item) + '.dump')
38+
_dump.write_text(dumps(loads(item.read_bytes())))
39+
# Get and accumulate dump size
40+
dumpSize[_dname] += _dump.stat().st_size
41+
# Remove dump
42+
_dump.unlink()
43+
44+
# Print summary
45+
_GB = (1024 * 1024 * 1024)
46+
origTotal = 0
47+
dumpTotal = 0
48+
for key, val in origSize.items():
49+
_dump = dumpSize[key]
50+
printSize(key, val, _dump)
51+
origTotal += val
52+
dumpTotal += _dump
53+
54+
printSize('Total', origTotal, dumpTotal)

0 commit comments

Comments
 (0)