update-bench.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /** Update Markdown files in /bench */
  2. import { BenchData, Markdown } from "./utils";
  3. (async () => {
  4. const bench = await BenchData.open();
  5. await BenchData.forEachMarkdown((markdown, fileName) => {
  6. if (fileName === "COMPUTE_UNITS.md") {
  7. const versions = bench.getVersions();
  8. // On the first version, compare with itself to update it with no changes
  9. versions.unshift(versions[0]);
  10. for (const i in versions) {
  11. const currentVersion = versions[i];
  12. const nextVersion = versions[+i + 1];
  13. if (currentVersion === "unreleased") {
  14. return;
  15. }
  16. const newComputeUnitsResult = bench.get(nextVersion).computeUnits;
  17. const oldComputeUnitsResult = bench.get(currentVersion).computeUnits;
  18. // Create table
  19. const table = Markdown.createTable(
  20. "Instruction",
  21. "Compute Units",
  22. "+/-"
  23. );
  24. bench.compareComputeUnits(
  25. newComputeUnitsResult,
  26. oldComputeUnitsResult,
  27. (ixName, newComputeUnits, oldComputeUnits) => {
  28. const percentChange = (
  29. (newComputeUnits / oldComputeUnits - 1) *
  30. 100
  31. ).toFixed(2);
  32. let changeText;
  33. if (isNaN(oldComputeUnits)) {
  34. changeText = "N/A";
  35. } else if (+percentChange > 0) {
  36. changeText = `🔴 **+${percentChange}%**`;
  37. } else {
  38. changeText = `🟢 **${percentChange}%**`;
  39. }
  40. table.insert(ixName, newComputeUnits.toString(), changeText);
  41. },
  42. (ixName, computeUnits) => {
  43. table.insert(
  44. ixName,
  45. computeUnits.toString(),
  46. +i === 0 ? "N/A" : "-"
  47. );
  48. }
  49. );
  50. // Update version's table
  51. markdown.updateTable(nextVersion, table);
  52. }
  53. }
  54. });
  55. })();