test json size
This commit is contained in:
parent
5a57f505cd
commit
4aa884f301
|
@ -0,0 +1,20 @@
|
|||
name: JSON size opt
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
|
||||
json:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- run: |
|
||||
for d in ./libraries/*; do
|
||||
git submodule update --init "$d"/latest
|
||||
done
|
||||
|
||||
- run: ./jsonsize.py
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from pathlib import Path
|
||||
from json import dumps, loads
|
||||
|
||||
ROOT = Path(__file__).resolve().parent / 'libraries'
|
||||
|
||||
def printSize(key, origSize, dumpSize):
|
||||
_GB = (1024 * 1024 * 1024)
|
||||
print(
|
||||
f'{key}:',
|
||||
origSize / _GB, 'GB',
|
||||
'->',
|
||||
dumpSize / _GB, 'GB',
|
||||
f"[{100*dumpSize/origSize}%]" if origSize != 0 else ""
|
||||
)
|
||||
|
||||
origSize = {}
|
||||
dumpSize = {}
|
||||
|
||||
# For each library
|
||||
for _dir in ROOT.iterdir():
|
||||
_dname = _dir.name
|
||||
|
||||
# Check latest version only
|
||||
_verdir = _dir / 'latest'
|
||||
|
||||
# Initialize size counters
|
||||
origSize[_dname] = 0
|
||||
dumpSize[_dname] = 0
|
||||
|
||||
# For each '*.lib.json' file (recursively)
|
||||
for item in _verdir.glob('**/*.lib.json'):
|
||||
# Get and accumulate size
|
||||
origSize[_dname] += item.stat().st_size
|
||||
# Read and dump
|
||||
_dump = Path(str(item) + '.dump')
|
||||
_dump.write_text(dumps(loads(item.read_bytes())))
|
||||
# Get and accumulate dump size
|
||||
dumpSize[_dname] += _dump.stat().st_size
|
||||
# Remove dump
|
||||
_dump.unlink()
|
||||
|
||||
# Print summary
|
||||
_GB = (1024 * 1024 * 1024)
|
||||
origTotal = 0
|
||||
dumpTotal = 0
|
||||
for key, val in origSize.items():
|
||||
_dump = dumpSize[key]
|
||||
printSize(key, val, _dump)
|
||||
origTotal += val
|
||||
dumpTotal += _dump
|
||||
|
||||
printSize('Total', origTotal, dumpTotal)
|
Loading…
Reference in New Issue