benchmark.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <html>
  2. <script nonce="{script_nonce}">
  3. window.benchmark_key = "{benchmark_key}";
  4. function setState(elem, text) {
  5. var formatted = text
  6. var parts = text.match(/\* Running (.*?)(\n|$)/g)
  7. if (parts) {
  8. for (var i=0; i < parts.length; i++) {
  9. part = parts[i];
  10. var details = part.match(/\* Running (.*?) (\.+|$)(.*)/);
  11. if (details) {
  12. var title = details[1]
  13. var progress = details[2]
  14. var result = details[3]
  15. result_parts = result.match(/(.*) Done in ([0-9\.]+)s = (.*?) \(([0-9\.]+)x\)/)
  16. var percent = Math.min(100, progress.length * 10)
  17. if (result_parts) percent = 100
  18. var style = "background-image: linear-gradient(90deg, #FFF " + percent + "%, #FFF 0%, #d9d5de 0%);"
  19. var part_formatted = "<div class='test' style='" + style + "'>"
  20. part_formatted += "<span class='title'>" + title + "</span><span class='percent percent-" + percent + "'>" + percent + "%</span> "
  21. if (result_parts) {
  22. var result_extra = result_parts[1]
  23. var taken = result_parts[2]
  24. var multipler_title = result_parts[3]
  25. var multipler = result_parts[4]
  26. part_formatted += "<div class='result result-" + multipler_title.replace(/[^A-Za-z]/g, "") + "'>"
  27. part_formatted += " <span class='taken'>" + taken + "s</span>"
  28. part_formatted += " <span class='multipler'>" + multipler + "x</span>"
  29. part_formatted += " <span class='multipler-title'>" + multipler_title + "</span>"
  30. part_formatted += "</div>"
  31. } else {
  32. part_formatted += "<div class='result'>" + result + "</div>"
  33. }
  34. part_formatted += "</div>"
  35. formatted = formatted.replace(part, part_formatted);
  36. }
  37. }
  38. }
  39. formatted = formatted.replace(/(\! Error:.*)/, "<div class='test error'>$1</div>");
  40. formatted = formatted.replace(/(\== Result ==[^]*)/, "<div class='test summary'>$1</div>");
  41. var is_bottom = document.body.scrollTop + document.body.clientHeight >= document.body.scrollHeight - 5;
  42. elem.innerHTML = formatted.trim();
  43. if (is_bottom)
  44. document.body.scrollTop = document.body.scrollHeight;
  45. }
  46. function stream(url, elem) {
  47. document.getElementById("h1").innerText = "Benchmark: Starting..."
  48. var xhr = new XMLHttpRequest();
  49. xhr.open('GET', url, true);
  50. xhr.setRequestHeader('Accept', 'text/html');
  51. xhr.send(null);
  52. xhr.onreadystatechange = function(state) {
  53. document.getElementById("h1").innerText = "Benchmark: Running..."
  54. setState(elem, xhr.responseText);
  55. if (xhr.readyState == 4) {
  56. document.getElementById("h1").innerText = "Benchmark: Done."
  57. }
  58. }
  59. }
  60. </script>
  61. <body>
  62. <style>
  63. body {
  64. background-color: #3c3546;
  65. background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23cfcfcf' fill-opacity='0.09'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");}
  66. h1 {
  67. font-family: monospace; color: white; font-weight: normal; text-transform: uppercase;
  68. max-width: 690px; margin: 30px auto; margin-bottom: 10px;
  69. }
  70. #out {
  71. white-space: pre-line; background-color: #ffffff1a; padding: 20px; font-family: Consolas, monospace;
  72. font-size: 11px; width: 90%; margin: auto; max-width: 650px; box-shadow: 0px 10px 30px -10px #5c5c5c6b;
  73. }
  74. .test { padding: 12px; box-shadow: 0px 5px 13px -5px #5c5c5c6b; margin-bottom: -2px; background-color: white; border: 1px solid #dbdbdb; }
  75. .test .percent { float: right; }
  76. .test .percent-100 { display: none; }
  77. .test .result { float: right; }
  78. .test .title { max-width: calc(100% - 150px); display: inline-block; }
  79. .test .multipler-title { display: inline-block; width: 50px; text-align: right; }
  80. .test:last-child { margin-bottom: 15px; border-color: #c1c1c1; }
  81. .test .result-Sloooow { color: red; }
  82. .test .result-Ehh { color: #ad1457; }
  83. .test .result-Goodish { color: #ef6c00; }
  84. .test .result-Ok { color: #00cf03; }
  85. .test .result-Fine { color: #00bcd4; }
  86. .test .result-Fast { color: #4b78ff; }
  87. .test .result-WOW { color: #9c27b0; }
  88. .test .result-Insane { color: #d603f4; }
  89. .test.summary { margin-top: 20px; text-transform: uppercase; border-left: 10px solid #00ff63; border-color: #00ff63; }
  90. .test.error { background-color: #ff2259; color: white; border-color: red; }
  91. #start { text-align: center }
  92. .button {
  93. background-color: white; padding: 10px 20px; display: inline-block; border-radius: 5px;
  94. text-decoration: none; color: #673AB7; text-transform: uppercase; margin-bottom: 11px; border-bottom: 2px solid #c1bff8;
  95. }
  96. .button:hover { border-bottom-color: #673AB7; }
  97. .button:active { transform: translateY(1px) }
  98. small { text-transform: uppercase; opacity: 0.7; color: white; letter-spacing: 1px; }
  99. </style>
  100. <h1 id="h1">Benchmark</h1>
  101. <div id="out">
  102. <div id="start">
  103. <a href="#Start" class="button" id="start_button">Start benchmark</a>
  104. <small>(It will take around 20 sec)</small>
  105. </div>
  106. </div>
  107. <script nonce="{script_nonce}">
  108. function start() {
  109. stream("/BenchmarkResult?benchmark_key={benchmark_key}&filter={filter}", document.getElementById("out"));
  110. return false;
  111. }
  112. document.getElementById("start_button").onclick = start
  113. </script>
  114. </body>
  115. </html>