"""
Benchmarks for encoding cache keys as JSON.
"""

from collections import defaultdict
import statistics
import time

from funkycache.key import encode_key_as_json
from test_key import KEY_ENCODING_TEST_CASES


if __name__ == "__main__":
    results = defaultdict(list)

    for _ in range(5000):
        for tc in KEY_ENCODING_TEST_CASES:
            t0 = time.perf_counter()
            encode_key_as_json(tc.values[0])  # type: ignore
            elapsed = time.perf_counter() - t0
            results[tc.id].append(elapsed)

    for name, data in results.items():
        print(f"{statistics.mean(data):.8f}\t{name}")
