mirror of
https://github.com/nlohmann/json.git
synced 2026-10-06 06:30:31 +00:00
Make the json_view comparison fair to fresh documents and robust
- compare.py: make --data, --corpus, and --build-dir absolute, since the benchmarks run in the build directory; download into a .part file and remove an archive whose SHA-256 does not match, so that an interrupted download is not kept - bench_view/bench_corpus/bench_edit: report files that cannot be opened instead of aborting; run each engine once untimed before its timed call, so that no engine pays for the allocator cleaning up after the previous one (with glibc, json_view after json::parse looked 1.7x slower on citm_catalog traverse); add "simdjson DOM (fresh)" and time "json_view (reused)" for traverse and select too - README: explain fresh vs. reused documents and page faults on Linux Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -154,11 +154,14 @@ def download_library(name, work):
|
||||
if not os.path.isfile(archive):
|
||||
print(f'downloading {pin["url"]}', flush=True)
|
||||
# the URLs are the https constants in PINNED, and the SHA-256 is checked below
|
||||
urllib.request.urlretrieve(pin['url'], archive) # nosec B310
|
||||
# (into a .part file first, so that an interrupted download is not kept)
|
||||
urllib.request.urlretrieve(pin['url'], archive + '.part') # nosec B310
|
||||
os.replace(archive + '.part', archive)
|
||||
with open(archive, 'rb') as f:
|
||||
digest = hashlib.sha256(f.read()).hexdigest()
|
||||
if digest != pin['sha256']:
|
||||
sys.exit(f'error: SHA-256 of {archive} is {digest}, expected {pin["sha256"]}')
|
||||
os.remove(archive) # downloaded again by the next run
|
||||
sys.exit(f'error: SHA-256 of {archive} is {digest}, expected {pin["sha256"]} (removed)')
|
||||
src = os.path.join(work, 'download', pin['dir'])
|
||||
if not os.path.isdir(src):
|
||||
with tarfile.open(archive) as t:
|
||||
@@ -214,6 +217,10 @@ def main():
|
||||
ap.add_argument('--corpus', nargs='*', default=[], help='more files for bench_corpus')
|
||||
ap.add_argument('--build-dir', default=os.path.join(HERE, 'build'), help='where to build (default: build/ next to this script)')
|
||||
args = ap.parse_args()
|
||||
# the benchmarks run in the build directory: make the paths absolute
|
||||
args.data = os.path.abspath(args.data)
|
||||
args.corpus = [os.path.abspath(f) for f in args.corpus]
|
||||
args.build_dir = os.path.abspath(args.build_dir)
|
||||
|
||||
cxx = os.environ.get('CXX', 'c++')
|
||||
cc = os.environ.get('CC', 'cc')
|
||||
|
||||
Reference in New Issue
Block a user