Skip to content

Commit

Permalink
test json size
Browse files Browse the repository at this point in the history
  • Loading branch information
umarcor committed Apr 17, 2021
1 parent db2e067 commit e7cd6ac
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/jsonsize.yml
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions jsonsize.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e7cd6ac

Please sign in to comment.