From 4aa884f30141c847c2102a9f99ef0de23f5581b1 Mon Sep 17 00:00:00 2001 From: umarcor Date: Sat, 17 Apr 2021 11:17:34 +0200 Subject: [PATCH] test json size --- .github/workflows/jsonsize.yml | 20 +++++++++++++ jsonsize.py | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 .github/workflows/jsonsize.yml create mode 100755 jsonsize.py diff --git a/.github/workflows/jsonsize.yml b/.github/workflows/jsonsize.yml new file mode 100644 index 000000000..b87fc702d --- /dev/null +++ b/.github/workflows/jsonsize.yml @@ -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 diff --git a/jsonsize.py b/jsonsize.py new file mode 100755 index 000000000..243bfd2c4 --- /dev/null +++ b/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)