Guest User

Untitled

a guest
Nov 21st, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. const express = require("express");
  2. const chroma = require("chroma-js");
  3. const fs = require("fs-extra");
  4.  
  5. const app = express();
  6.  
  7. const scaleGood = chroma.scale(["blue", "green"]);
  8. const scaleOk = chroma.scale(["yellow", "orange"]);
  9. const scaleBad = chroma.scale(["red", "black"]);
  10.  
  11. let gcc = new Map([
  12. ["cell.l4", 310422],
  13. ["collatz.l4", 89811],
  14. ["fibrec.l4", 164551],
  15. ["floyd.l4", 191644],
  16. ["gcd.l4", 245165],
  17. ["list.l4", 354856],
  18. ["mmult2.l4", 167739],
  19. ["mmult.l4", 292616],
  20. ["msort.l4", 97452],
  21. ["prime.l4", 83499],
  22. ["qsort.l4", 321400],
  23. ["shifts.l4", 94324],
  24. ["tree.l4", 139278],
  25. ["avl.l4", 5724362],
  26. ["hashtable.l4", 1446232],
  27. ["heaps.l4", 6023667],
  28. ["md5.l4", 2557570]
  29. ]);
  30.  
  31.  
  32.  
  33. app.get("/", (req, res) => {
  34. fs.readFile("last.log")
  35. .then((data) => {
  36. data = data.toString();
  37. data = data.split(/-- Timing file .*\/([a-z0-9]+\.l4) --/);
  38. data = data.slice(1);
  39.  
  40. map = new Map();
  41.  
  42. for (let i = 0; i < data.length; i += 2) {
  43. let key = data[i];
  44. let value =
  45. data[i+1]
  46. .split("\n")
  47. .slice(1,7)
  48. .map((v) => {
  49. let match = /.*?(\d{3,}).*/.exec(v);
  50. return match === null ? null : parseInt(match[1]);
  51. })
  52. value = value.reduce((a, b) => a == null ? null : (b == null ? null : Math.min(a, b)));
  53. map.set(key, value);
  54. }
  55.  
  56. let out = `
  57. <html>
  58. <head><style>th, td { padding: .4em }</style></head>
  59. <body>
  60. <h1>Testing Results</h1>
  61. <table>
  62. <tr><th>Test file</th><th>Your Cycles</th><th>GCC Cycles</th><th>Performance</th></tr>`;
  63.  
  64. let perfScore = 0;
  65.  
  66. for (let [file, gccCycles] of gcc) {
  67. let yourCycles = map.get(file);
  68.  
  69. if (yourCycles == null) {
  70. out += `\n<tr style="background-color: black; color: white;"><td>${file}</td><td><b>FAILED</b></td><td>${gccCycles}</td><td><b>FAILED</b></td></tr>`;
  71. perfScore = NaN;
  72. } else {
  73. let perf = yourCycles / gccCycles;
  74. let color = "red";
  75. if (perf <= .7){
  76. color = scaleGood(perf / .7);
  77. } else if (perf <= 1) {
  78. color = scaleOk((perf - .7) / .3);
  79. } else {
  80. color = scaleBad((perf - 1) / .4);
  81. }
  82. out += `\n<tr style="background-color: ${color.hex()}; color: white;"><td>${file}</td><td>${yourCycles}</td><td>${gccCycles}</td><td>${Math.round(perf*1000)/1000}</td></tr>`;
  83. perfScore += perf;
  84. }
  85. }
  86.  
  87. perfScore /= gcc.size;
  88.  
  89. out += `\n</table><h2>Final perf score: ${isNaN(perfScore) ? "FAILED" : Math.round(perfScore*10000)/10000}</body></html>`;
  90. res.send(out);
  91. });
  92. });
  93.  
  94. app.listen(1337);
  95. console.log("Listening on *:1337");
Add Comment
Please, Sign In to add comment