Skip to content

Instantly share code, notes, and snippets.

@mbollmann
Created February 20, 2026 16:22
Show Gist options
  • Select an option

  • Save mbollmann/4a9a39a6930de00f152942e89b7f4344 to your computer and use it in GitHub Desktop.

Select an option

Save mbollmann/4a9a39a6930de00f152942e89b7f4344 to your computer and use it in GitHub Desktop.
Timing YAML vs. JSON parsing of the ACL Anthology people database
import msgspec
import timeit
import yaml
from yaml import CLoader
yaml_path = "../data/yaml/people.yaml"
json_path = "../data/yaml/people.json"
def load_yaml():
with open(yaml_path, "r", encoding="utf-8") as f:
data = yaml.load(f, Loader=CLoader)
return data
def load_json():
with open(json_path, "rb") as f:
data = msgspec.json.decode(f.read())
return data
# Make sure JSON file exists and is equivalent to the YAML file
with open(json_path, "wb") as f:
f.write(msgspec.json.encode(load_yaml()))
yaml_time = timeit.timeit("load_yaml()", globals=globals(), number=20)
json_time = timeit.timeit("load_json()", globals=globals(), number=20)
print(f"YAML loading took {yaml_time:2.2f}s")
print(f"JSON loading took {json_time:2.2f}s")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment