compare_benchmarks.py 948 B

123456789101112131415161718192021222324252627282930
  1. import os
  2. import os.path
  3. import json
  4. comparisons = []
  5. for (root, _dirs, files) in os.walk('target/criterion'):
  6. for file in files:
  7. if file == 'estimates.json' and root.endswith(
  8. 'new') and 'TinyVec' in root:
  9. path = os.path.join(root, file)
  10. bench_name = path.split('/')[3]
  11. tinyvec_time = json.load(open(path))['mean']['point_estimate']
  12. path = path.replace('TinyVec', 'SmallVec')
  13. smallvec_time = json.load(open(path))['mean']['point_estimate']
  14. comparisons.append((bench_name, tinyvec_time / smallvec_time))
  15. comparisons.sort(key=lambda x: x[1])
  16. longest_name = max(len(c[0]) for c in comparisons)
  17. for (name, ratio) in comparisons:
  18. # Undo the criterion name mangling
  19. name = name.replace('_[', '<[')
  20. name = name.replace(']___', ']>::')
  21. name = name.ljust(longest_name)
  22. print(f"{name} {ratio:.2f}")