OLD | NEW |
(Empty) | |
| 1 (function(){ |
| 2 |
| 3 // Populated from: http://www.medcalc.be/manual/t-distribution.php |
| 4 // 95% confidence for N - 1 = 4 |
| 5 var tDistribution = 2.776; |
| 6 |
| 7 // The number of individual test iterations to do |
| 8 var numTests = 5; |
| 9 |
| 10 // The type of run that we're doing (options are "runs/s" or "ms") |
| 11 var runStyle = "runs/s"; |
| 12 |
| 13 // A rough estimate, in seconds, of how long it'll take each test |
| 14 // iteration to run |
| 15 var timePerTest = runStyle === "runs/s" ? 1 : 0.5; |
| 16 |
| 17 // Initialize a batch of tests |
| 18 // name = The name of the test collection |
| 19 this.startTest = function(name, version){ |
| 20 numloaded++; |
| 21 if ( numloaded == totalTests ) |
| 22 setTimeout( init, 100 ); |
| 23 |
| 24 testName = name; |
| 25 if ( !queues[testName] ) return; |
| 26 testID = testName; |
| 27 testNames[testID] = testName; |
| 28 testVersions[testID] = version || 0; |
| 29 testSummary[testID] = testSummaryNum[testID] = testDone[testID]
= testNum[testID] = 0; |
| 30 |
| 31 queues[testID].push(function(){ |
| 32 summary = 0; |
| 33 dequeue(); |
| 34 }); |
| 35 }; |
| 36 |
| 37 // Anything that you want to have run in order, but not actually test |
| 38 this.prep = function(fn){ |
| 39 if ( !queues[testName] ) return; |
| 40 queues[testID].push(function(){ |
| 41 fn(); |
| 42 dequeue(); |
| 43 }); |
| 44 }; |
| 45 |
| 46 // End the tests and finalize the report |
| 47 this.endTest = function(){ |
| 48 if ( !queues[testName] ) return; |
| 49 // Save the summary output until all the test are complete |
| 50 queues[testID].push(function(){ |
| 51 dequeue(); |
| 52 }); |
| 53 }; |
| 54 |
| 55 // Run a new test |
| 56 // name = The unique name of the test |
| 57 // num = The 'length' of the test (length of string, # of tests, etc.) |
| 58 // fn = A function holding the test to run |
| 59 this.test = function(name, num, fn){ |
| 60 if ( !queues[testName] ) return; |
| 61 // Save the summary output until all the test are complete |
| 62 var curTest = testName, curID = testID; |
| 63 |
| 64 if ( arguments.length === 3 ) { |
| 65 if ( !nameDone[name] ) |
| 66 nameDone[name] = 0; |
| 67 nameDone[name]++; |
| 68 |
| 69 if ( nameDone[name] != 3 ) |
| 70 return; |
| 71 } else { |
| 72 fn = num; |
| 73 num = 1; |
| 74 } |
| 75 |
| 76 time += timePerTest * numTests; |
| 77 |
| 78 testNum[curID]++; |
| 79 |
| 80 // Don't execute the test immediately |
| 81 queues[testID].push(function(){ |
| 82 title = name; |
| 83 var times = [], start, pos = 0, cur; |
| 84 |
| 85 setTimeout(function(){ |
| 86 // run tests |
| 87 try { |
| 88 if ( doShark(name) ) { |
| 89 connectShark(); |
| 90 startShark(); |
| 91 } |
| 92 |
| 93 start = (new Date()).getTime(); |
| 94 |
| 95 if ( runStyle === "runs/s" ) { |
| 96 var runs = 0; |
| 97 |
| 98 cur = (new Date()).getTime(); |
| 99 |
| 100 while ( (cur - start) < 1000 ) { |
| 101 fn(); |
| 102 cur = (new Date()).getTi
me(); |
| 103 runs++; |
| 104 } |
| 105 } else { |
| 106 fn(); |
| 107 cur = (new Date()).getTime(); |
| 108 } |
| 109 |
| 110 if ( doShark(name) ) { |
| 111 stopShark(); |
| 112 disconnectShark(); |
| 113 } |
| 114 |
| 115 // For making Median and Variance |
| 116 if ( runStyle === "runs/s" ) { |
| 117 times.push( (runs * 1000) / (cur
- start) ); |
| 118 } else { |
| 119 times.push( cur - start ); |
| 120 } |
| 121 } catch( e ) { |
| 122 alert("FAIL " + name + " " + num + e); |
| 123 return; |
| 124 } |
| 125 |
| 126 if ( pos < numTests ) { |
| 127 updateTime(); |
| 128 updateTestPos({curID: curID, collection:
testNames[curID], version: testVersions[curID]}); |
| 129 } |
| 130 |
| 131 if ( ++pos < numTests ) { |
| 132 setTimeout( arguments.callee, 1 ); |
| 133 |
| 134 } else { |
| 135 var data = compute( times, numTests ); |
| 136 |
| 137 data.curID = curID; |
| 138 data.collection = testNames[curID]; |
| 139 data.version = testVersions[curID]; |
| 140 data.name = title; |
| 141 data.scale = num; |
| 142 |
| 143 logTest(data); |
| 144 |
| 145 dequeue(); |
| 146 } |
| 147 }, 1); |
| 148 }); |
| 149 |
| 150 function compute(times, runs){ |
| 151 var results = {runs: runs}, num = times.length; |
| 152 |
| 153 times = times.sort(function(a,b){ |
| 154 return a - b; |
| 155 }); |
| 156 |
| 157 // Make Sum |
| 158 results.sum = 0; |
| 159 |
| 160 for ( var i = 0; i < num; i++ ) |
| 161 results.sum += times[i]; |
| 162 |
| 163 // Make Min |
| 164 results.min = times[0]; |
| 165 |
| 166 // Make Max |
| 167 results.max = times[ num - 1 ]; |
| 168 |
| 169 // Make Mean |
| 170 results.mean = results.sum / num; |
| 171 |
| 172 // Make Median |
| 173 results.median = num % 2 == 0 ? |
| 174 (times[Math.floor(num/2)] + times[Math.ceil(num/
2)]) / 2 : |
| 175 times[Math.round(num/2)]; |
| 176 |
| 177 // Make Variance |
| 178 results.variance = 0; |
| 179 |
| 180 for ( var i = 0; i < num; i++ ) |
| 181 results.variance += Math.pow(times[i] - results.
mean, 2); |
| 182 |
| 183 results.variance /= num - 1; |
| 184 |
| 185 // Make Standard Deviation |
| 186 results.deviation = Math.sqrt( results.variance ); |
| 187 |
| 188 // Compute Standard Errors Mean |
| 189 results.sem = (results.deviation / Math.sqrt(results.run
s)) * tDistribution; |
| 190 |
| 191 // Error |
| 192 results.error = ((results.sem / results.mean) * 100) ||
0; |
| 193 |
| 194 return results; |
| 195 } |
| 196 }; |
| 197 |
| 198 // All the test data |
| 199 var tests; |
| 200 |
| 201 // The number of test files to load |
| 202 var totalTests = 0; |
| 203 |
| 204 // The number of test files loaded |
| 205 var numloaded = 0; |
| 206 |
| 207 // Queue of functions to run |
| 208 var queue = []; |
| 209 var queues = {}; |
| 210 |
| 211 var catnames = { |
| 212 dromaeo: "Dromaeo JavaScript Tests", |
| 213 sunspider: "SunSpider JavaScript Tests", |
| 214 "v8": "V8 JavaScript Tests", |
| 215 dom: "DOM Core Tests", |
| 216 jslib: "JavaScript Library Tests", |
| 217 cssquery: "CSS Selector Tests" |
| 218 }; |
| 219 |
| 220 |
| 221 var testElems = {}; |
| 222 var testNum = {}; |
| 223 var testDone = {}; |
| 224 var testNames = {}; |
| 225 var testVersions = {}; |
| 226 var dataStore = []; |
| 227 var names = []; |
| 228 var interval; |
| 229 var totalTime = 0; |
| 230 var time = 0; |
| 231 var title, testName, testID, testSummary = {} , testSummaryNum = {}, max
Total = 0, maxTotalNum = 0; |
| 232 var nameDone = {}; |
| 233 |
| 234 // Query String Parsing |
| 235 var search = (window.location.search || "?").substr(1); |
| 236 |
| 237 search = search.replace(/&runStyle=([^&]+)/, function(all, type){ |
| 238 runStyle = type; |
| 239 return ""; |
| 240 }); |
| 241 |
| 242 var parts = search.split("&"); |
| 243 |
| 244 if ( parts[0] === "recommended" ) { |
| 245 parts[0] = "dromaeo|sunspider|v8|dom|jslib"; |
| 246 } |
| 247 |
| 248 var none = !parts[0] || parts[0].match(/=/); |
| 249 var filter = parts.length && !parts[0].match(/=/) && parts[0] !== "all"
? |
| 250 new RegExp(parts.shift(), "i") : |
| 251 /./; |
| 252 |
| 253 // To enable shark debugging add &shark to the end of the URL |
| 254 var doShark = function(name) { return false; }; |
| 255 for ( var i = 0; i < parts.length; i++ ) { |
| 256 var m = /^shark(?:=(.*))?$/.exec(parts[i]); |
| 257 if (m) { |
| 258 if (m[1] === undefined) { |
| 259 doShark = function(name) { return true; }; |
| 260 } |
| 261 else { |
| 262 var sharkMatch = new RegExp(m[1]); |
| 263 doShark = function(name) { |
| 264 return sharkMatch.test(name); |
| 265 }; |
| 266 } |
| 267 } |
| 268 |
| 269 m = /^numTests=(\d+)$/.exec(parts[i]); |
| 270 if (m) |
| 271 numTests = Number(m[1]); |
| 272 } |
| 273 |
| 274 jQuery(function(){ |
| 275 var id = search.match(/id=([\d,]+)/); |
| 276 |
| 277 if ( none && !id ) { |
| 278 $("#overview").hide(); |
| 279 return; |
| 280 } |
| 281 |
| 282 var cat = filter.toString().slice(1,-2); |
| 283 |
| 284 if ( catnames[cat] ) { |
| 285 $("#overview span:first").html( catnames[cat] ); |
| 286 |
| 287 if ( catnames[cat].length > 22 ) { |
| 288 $("#overview span:first").css("font-size", 22); |
| 289 } |
| 290 } |
| 291 |
| 292 $("#tests").hide(); |
| 293 |
| 294 jQuery.getJSON("tests/MANIFEST.json", function(json){ |
| 295 tests = json; |
| 296 |
| 297 names = []; |
| 298 |
| 299 for ( var name in tests ) |
| 300 // Don't load tests that we aren't looking for |
| 301 if ( filter.test( name ) ) |
| 302 names.push( name ); |
| 303 |
| 304 names = names.sort(function(a, b){ |
| 305 return tests[a].name < tests[b].name ? -1 : |
| 306 tests[a].name == tests[b].name ? 0 : 1; |
| 307 }); |
| 308 |
| 309 // Check if we're loading a specific result set |
| 310 // ?id=NUM |
| 311 if ( id ) { |
| 312 jQuery.ajax({ |
| 313 url: "store.php?id=" + id[1], |
| 314 dataType: "json", |
| 315 success: function(data){ |
| 316 resultsLoaded(id[1], data); |
| 317 } |
| 318 }); |
| 319 |
| 320 // Otherwise we're loading a normal set of tests |
| 321 } else { |
| 322 $("#wrapper").append("<br style='clear:both;'/><
center><a href='?" + names.join("|") + "'>Re-run tests</a></center>"); |
| 323 |
| 324 for ( var i = 0; i < names.length; i++ ) (functi
on(name){ |
| 325 var test = tests[name]; |
| 326 |
| 327 queues[name] = []; |
| 328 makeElem(name); |
| 329 initTest(name); |
| 330 |
| 331 totalTests++; |
| 332 |
| 333 // Check if we're loading an HTML file |
| 334 if ( test.file.match(/html$/) ) { |
| 335 var iframe = document.createElem
ent("iframe"); |
| 336 iframe.style.height = "1px"; |
| 337 iframe.style.width = "1px"; |
| 338 iframe.src = "tests/" + test.fil
e; |
| 339 document.body.appendChild( ifram
e ); |
| 340 |
| 341 // Otherwise we're loading a pure-JS tes
t |
| 342 } else { |
| 343 jQuery.getScript("tests/" + test
.file); |
| 344 } |
| 345 })(names[i]); |
| 346 } |
| 347 }); |
| 348 }); |
| 349 |
| 350 // Remove the next test from the queue and execute it |
| 351 function dequeue(){ |
| 352 if ( interval && queue.length ) { |
| 353 queue.shift()(); |
| 354 |
| 355 } else if ( queue.length == 0 ) { |
| 356 interval = false; |
| 357 time = 0; |
| 358 |
| 359 $("#overview input").remove(); |
| 360 updateTimebar(); |
| 361 |
| 362 if ( dataStore && dataStore.length ) { |
| 363 $("body").addClass("alldone"); |
| 364 var div = jQuery("<div class='results'>Saving...
</div>").insertBefore("#overview"); |
| 365 jQuery.ajax({ |
| 366 type: "POST", |
| 367 url: "store.php", |
| 368 data: "data=" + encodeURIComponent(JSON.
stringify(dataStore)) + "&style=" + runStyle, |
| 369 success: function(id){ |
| 370 var url = window.location.href.r
eplace(/\?.*$/, "") + "?id=" + id; |
| 371 div.html("Results saved. You can
access them at a later time at the following URL:<br/><strong><a href='" + url
+ "'>" + url + "</a></strong></div>"); |
| 372 } |
| 373 }); |
| 374 } |
| 375 } |
| 376 } |
| 377 |
| 378 function updateTimebar(){ |
| 379 $("#timebar").html("<span><strong>" + (runStyle === "runs/s" ? M
ath.pow(Math.E, maxTotal / maxTotalNum) : maxTotal).toFixed(2) + "</strong>" + r
unStyle + " (Total)</span>"); |
| 380 } |
| 381 |
| 382 // Run once all the test files are fully loaded |
| 383 function init(){ |
| 384 for ( var n = 0; n < names.length; n++ ) { |
| 385 queue = queue.concat( queues[ names[n] ] ); |
| 386 } |
| 387 |
| 388 totalTime = time; |
| 389 time += timePerTest; |
| 390 updateTime(); |
| 391 |
| 392 $("#pause") |
| 393 .val("Run") |
| 394 .click(function(){ |
| 395 if ( interval ) { |
| 396 interval = null; |
| 397 this.value = "Run"; |
| 398 } else { |
| 399 if ( !interval ) { |
| 400 interval = true; |
| 401 dequeue(); |
| 402 } |
| 403 this.value = "Pause"; |
| 404 } |
| 405 }); |
| 406 } |
| 407 |
| 408 function initTest(curID){ |
| 409 $("<div class='result-item'></div>") |
| 410 .append( testElems[ curID ] ) |
| 411 .append( "<p>" + (tests[curID] ? tests[ curID ].desc : "
") + "<br/><a href='" + |
| 412 (tests[curID] && tests[curID].origin ? tests[ cu
rID ].origin[1] : "") + "'>Origin</a>, <a href='tests/" + |
| 413 (tests[curID] ? tests[ curID ].file : "") + "'>S
ource</a>, <b>Tests:</b> " + |
| 414 (tests[curID] && tests[curID].tags ? tests[ curI
D ].tags.join(", ") : "") + "</p>" ) |
| 415 .append( "<ol class='results'></ol>" ) |
| 416 .appendTo("#main"); |
| 417 } |
| 418 |
| 419 function resultsLoaded(id, datas){ |
| 420 var results = {}; |
| 421 var runs = {}; |
| 422 var output = ""; |
| 423 var excluded = []; |
| 424 var overview = document.getElementById("overview"); |
| 425 |
| 426 for ( var d = 0; d < datas.length; d++ ) { |
| 427 var data = datas[d]; |
| 428 |
| 429 runStyle = data.style; |
| 430 |
| 431 if ( datas.length == 1 ) { |
| 432 $("#overview").before("<div class='results'>View
ing test run #" + id + |
| 433 ", run on: " + data.created_at + " by:<b
r>" + data.useragent + "</div>"); |
| 434 } |
| 435 |
| 436 runs[data.id] = data; |
| 437 runs[data.id].mean = 0; |
| 438 runs[data.id].error = 0; |
| 439 runs[data.id].num = 0; |
| 440 runs[data.id].name = (data.useragent.match(/(MSIE [\d.]+
)/) || |
| 441 data.useragent.match(/((?:WebKit|Firefox|Shireto
ko|Opera)\/[\w.]+)/) || [0,data.id])[1]; |
| 442 |
| 443 for ( var i = 0; i < data.results.length; i++ ) { |
| 444 var result = data.results[i]; |
| 445 var curID = result.collection; |
| 446 var run = result.run_id; |
| 447 |
| 448 result.version += data.style; |
| 449 |
| 450 if ( !results[curID] ) |
| 451 results[curID] = {tests:{}, total:{}, ve
rsion: result.version}; |
| 452 |
| 453 if ( results[curID].version == result.version )
{ |
| 454 if ( !results[curID].total[run] ) { |
| 455 results[curID].total[run] = {max
:0, mean:0, median:0, min:0, deviation:0, error:0, num:0}; |
| 456 results[curID].tests[run] = []; |
| 457 } |
| 458 |
| 459 result.error = ((((result.deviation / Ma
th.sqrt(result.runs)) * tDistribution) / result.mean) * 100) || 0; |
| 460 results[curID].tests[run].push( result )
; |
| 461 |
| 462 var error = (parseFloat(result.error) /
100) * parseFloat(result.mean); |
| 463 error = (runStyle === "ms" ? error : err
or == 0 ? 0 : Math.log(error)); |
| 464 var total = results[curID].total[run]; |
| 465 total.num++; |
| 466 |
| 467 for ( var type in total ) { |
| 468 if ( type == "error" ) { |
| 469 total.error += error; |
| 470 } else if ( type == "mean" ) { |
| 471 total.mean += (runStyle
=== "ms" ? parseFloat(result.mean) : Math.log(parseFloat(result.mean))); |
| 472 } else if ( type !== "num" ) { |
| 473 total[type] += parseFloa
t(result[type]); |
| 474 } |
| 475 } |
| 476 |
| 477 runs[run].num++; |
| 478 runs[run].mean += runStyle === "ms" ? pa
rseFloat(result.mean) : Math.log(parseFloat(result.mean)); |
| 479 runs[run].error += error; |
| 480 } |
| 481 } |
| 482 } |
| 483 |
| 484 var runTests = []; |
| 485 |
| 486 if ( datas.length == 1 ) { |
| 487 $("body").addClass("alldone"); |
| 488 |
| 489 for ( var i = 0; i < data.results.length; i++ ) { |
| 490 var item = data.results[i]; |
| 491 var result = item.curID = item.collection; |
| 492 |
| 493 if ( !filter.test(result) ) |
| 494 continue; |
| 495 |
| 496 if ( !testElems[result] ) { |
| 497 runTests.push(result); |
| 498 makeElem( result ); |
| 499 initTest( result ); |
| 500 } |
| 501 |
| 502 // Compute Standard Errors Mean |
| 503 item.sem = (item.deviation / Math.sqrt(item.runs
)) * tDistribution; |
| 504 |
| 505 // Error |
| 506 item.error = ((item.sem / item.mean) * 100) || 0
; |
| 507 |
| 508 logTest( item ); |
| 509 |
| 510 // testDone, testNum, testSummary |
| 511 testDone[ result ] = numTests - 1; |
| 512 testNum[ result ] = 1; |
| 513 |
| 514 updateTestPos( item ); |
| 515 } |
| 516 |
| 517 $("div.result-item").addClass("done"); |
| 518 |
| 519 totalTime = time = timePerTest; |
| 520 updateTime(); |
| 521 |
| 522 $("#overview input").remove(); |
| 523 updateTimebar(); |
| 524 } else { |
| 525 // Remove results where there is only one comparison set |
| 526 for ( var id in results ) { |
| 527 var num = 0; |
| 528 |
| 529 for ( var ntest in results[id].tests ) { |
| 530 num++; |
| 531 if ( num > 1 ) |
| 532 break; |
| 533 } |
| 534 |
| 535 if ( num <= 1 ) { |
| 536 excluded.push( id ); |
| 537 delete results[id]; |
| 538 } |
| 539 } |
| 540 |
| 541 var preoutput = "<tr><td></td>"; |
| 542 for ( var run in runs ) |
| 543 preoutput += "<th><a href='?id=" + run + "'>" +
runs[run].name + "</a></th>"; |
| 544 //preoutput += "<th>Winning %</th></tr>"; |
| 545 preoutput += "</tr>"; |
| 546 |
| 547 for ( var result in results ) { |
| 548 // Skip results that we're filtering out |
| 549 if ( !filter.test(result) ) |
| 550 continue; |
| 551 |
| 552 runTests.push(result); |
| 553 |
| 554 if ( runStyle === "runs/s" ) { |
| 555 for ( var run in runs ) { |
| 556 var mean = results[result].total
[run].mean - 0; |
| 557 var error = results[result].tota
l[run].error - 0; |
| 558 |
| 559 mean = Math.pow(Math.E, mean / r
esults[result].total[run].num); |
| 560 error = Math.pow(Math.E, error /
results[result].total[run].num); |
| 561 results[result].total[run].mean
= mean; |
| 562 results[result].total[run].error
= error; |
| 563 } |
| 564 } |
| 565 |
| 566 var name = tests[result] ? tests[result].name :
result; |
| 567 var tmp = processWinner(results[result].total); |
| 568 |
| 569 output += "<tr><th class='name'><span onclick='t
oggleResults(this.nextSibling);'>▶ </span>" + |
| 570 "<a href='' onclick='return toggleResult
s(this);'>" + name + "</a></th>"; |
| 571 |
| 572 for ( var run in runs ) { |
| 573 var mean = results[result].total[run].me
an - 0; |
| 574 var error = results[result].total[run].e
rror - 0; |
| 575 |
| 576 output += "<td class='" + (tmp[run] || '
') + "'>" + mean.toFixed(2) + "<small>" + runStyle + " ±" + ((error / mean)
* 100).toFixed(2) + "%</small></td>"; |
| 577 } |
| 578 |
| 579 //showWinner(tmp); |
| 580 output += "</tr>"; |
| 581 |
| 582 var _tests = results[result].tests, _data = _tes
ts[run], _num = _data.length; |
| 583 for ( var i = 0; i < _num; i++ ) { |
| 584 output += "<tr class='onetest hidden'><t
d><small>" + _data[i].name + "</small></td>"; |
| 585 for ( var run in runs ) { |
| 586 output += "<td>" + (_tests[run][
i].mean - 0).toFixed(2) + "<small>" + runStyle + " ±" + (_tests[run][i].err
or - 0).toFixed(2) + "%</small></td>"; |
| 587 } |
| 588 output += "<td></td></tr>"; |
| 589 } |
| 590 } |
| 591 |
| 592 if ( runStyle === "runs/s" ) { |
| 593 for ( var run in runs ) { |
| 594 runs[run].mean = Math.pow(Math.E, runs[r
un].mean / runs[run].num); |
| 595 runs[run].error = Math.pow(Math.E, runs[
run].error / runs[run].num); |
| 596 } |
| 597 } |
| 598 |
| 599 var tmp = processWinner(runs); |
| 600 var totaloutput = ""; |
| 601 |
| 602 if ( runStyle === "ms" ) { |
| 603 totaloutput += "<tr><th class='name'>Total:</th>
"; |
| 604 } else { |
| 605 totaloutput += "<tr><th class='name'>Total Score
:</th>"; |
| 606 } |
| 607 |
| 608 for ( var run in runs ) { |
| 609 totaloutput += "<th class='name " + (tmp[run] ||
'') + "' title='" + (tmp[run + "title"] || '') + "'>" + runs[run].mean.toFixed(
2) + "<small>" + runStyle + " ±" + ((runs[run].error / runs[run].mean) * 10
0).toFixed(2) + "%</small></th>"; |
| 610 } |
| 611 |
| 612 //showWinner(tmp); |
| 613 totaloutput += "</tr>"; |
| 614 |
| 615 overview.className = ""; |
| 616 overview.innerHTML = "<div class='resultwrap'><table cla
ss='results'>" + preoutput + totaloutput + output + totaloutput + "</table>" + (
excluded.length ? "<div style='text-align:left;'><small><b>Excluded Tests:</b> "
+ excluded.sort().join(", ") + "</small></div>" : "") + "</div>"; |
| 617 } |
| 618 |
| 619 $("#wrapper").append("<center><a href='?" + runTests.join("|") +
"'>Re-run tests</a></center>"); |
| 620 |
| 621 function showWinner(tmp){ |
| 622 if ( datas.length > 1 ) { |
| 623 if ( tmp.tie ) |
| 624 output += "<th>Tie</th>"; |
| 625 else |
| 626 output += "<th>" + tmp.diff + "%</th>"; |
| 627 } |
| 628 } |
| 629 } |
| 630 |
| 631 this.toggleResults = function(elem){ |
| 632 var span = elem.previousSibling; |
| 633 |
| 634 elem.blur(); |
| 635 elem = elem.parentNode.parentNode.nextSibling; |
| 636 |
| 637 span.innerHTML = elem.className.indexOf("hidden") < 0 ? "▶
" : "▼ "; |
| 638 |
| 639 while ( elem && elem.className.indexOf("onetest") >= 0 ) { |
| 640 elem.className = "onetest" + (elem.className.indexOf("hi
dden") >= 0 ? " " : " hidden"); |
| 641 elem = elem.nextSibling; |
| 642 } |
| 643 |
| 644 return false; |
| 645 }; |
| 646 |
| 647 function updateTime(){ |
| 648 time -= timePerTest; |
| 649 $("#left").html(Math.floor(time / 60) + ":" + (time % 60 < 10 ?
"0" : "" ) + Math.floor(time % 60)); |
| 650 |
| 651 var w = ((totalTime - time) / totalTime) * 100; |
| 652 |
| 653 $("#timebar").width((w < 1 ? 1 : w) + "%"); |
| 654 } |
| 655 |
| 656 function logTest(data){ |
| 657 // Keep a running summary going |
| 658 data.mean = parseFloat(data.mean); |
| 659 var mean = (runStyle === "runs/s" ? Math.log(data.mean) : data.m
ean); |
| 660 testSummary[data.curID] = (testSummary[data.curID] || 0) + mean; |
| 661 testSummaryNum[data.curID] = (testSummaryNum[data.curID] || 0) +
1; |
| 662 |
| 663 maxTotal += mean; |
| 664 maxTotalNum++; |
| 665 |
| 666 testDone[data.curID]--; |
| 667 updateTestPos(data); |
| 668 |
| 669 testElems[data.curID].next().next().append("<li><b>" + data.name
+ |
| 670 ":</b> " + data.mean.toFixed(2) + "<small>" + runStyle +
" ±" + data.error.toFixed(2) + "%</small></li>"); |
| 671 |
| 672 dataStore.push(data); |
| 673 } |
| 674 |
| 675 function updateTestPos(data, update){ |
| 676 if ( !update ) |
| 677 testDone[data.curID]++; |
| 678 |
| 679 var per = (testDone[data.curID] / (testNum[data.curID] * numTest
s)) * 100; |
| 680 |
| 681 if ( update ) |
| 682 per = 1; |
| 683 |
| 684 var mean = (runStyle === "runs/s" ? |
| 685 Math.pow(Math.E, testSummary[data.curID] / testSummaryNu
m[data.curID]) : |
| 686 testSummary[data.curID]); |
| 687 |
| 688 testElems[data.curID].html("<b>" + (tests[data.curID] ? tests[da
ta.curID].name : data.curID) + |
| 689 ":</b> <div class='bar'><div style='width:" + |
| 690 per + "%;'>" + (per >= 100 ? "<span>" + mean.toFixed(2)
+ runStyle + "</span>" : "") + "</div></div>"); |
| 691 |
| 692 if ( per >= 100 && testSummary[data.curID] > 0 ) { |
| 693 testElems[data.curID].parent().addClass("done"); |
| 694 } |
| 695 } |
| 696 |
| 697 function processWinner(data){ |
| 698 var minVal = -1, min2Val = -1, min, min2; |
| 699 |
| 700 for ( var i in data ) { |
| 701 var total = data[i].mean; |
| 702 if ( minVal == -1 || (runStyle === "ms" && total <= minV
al || runStyle === "runs/s" && total >= minVal) ) { |
| 703 min2Val = minVal; |
| 704 min2 = min; |
| 705 minVal = total; |
| 706 min = i; |
| 707 } else if ( min2Val == -1 || (runStyle === "ms" && total
<= minVal || runStyle === "runs/s" && total >= min2Val) ) { |
| 708 min2Val = total; |
| 709 min2 = i; |
| 710 } |
| 711 } |
| 712 |
| 713 var tieVal = (runStyle === "ms" ? minVal : min2Val) + data[min].
error + data[min2].error; |
| 714 |
| 715 var ret = { |
| 716 winner: min, |
| 717 diff: runStyle === "ms" ? |
| 718 -1 * Math.round((1 - (min2Val / minVal)) * 100)
: |
| 719 Math.round(((minVal / min2Val) - 1) * 100), |
| 720 tie: minVal == min2Val || (runStyle === "ms" ? tieVal >=
min2Val : tieVal >= minVal) |
| 721 }; |
| 722 |
| 723 ret.tie = ret.tie || ret.diff == 0; |
| 724 |
| 725 if ( ret.tie ) { |
| 726 ret[ min ] = 'tie'; |
| 727 ret[ min2 ] = 'tie'; |
| 728 ret[ min + 'title' ] = "Tied with another run."; |
| 729 ret[ min2 + 'title' ] = "Tied with another run."; |
| 730 } else { |
| 731 ret[ min ] = 'winner'; |
| 732 if ( min2Val > -1 ) { |
| 733 ret[ min + 'title' ] = "Won by " + ret.diff + "%
."; |
| 734 } |
| 735 } |
| 736 |
| 737 return ret; |
| 738 } |
| 739 |
| 740 function makeElem(testID){ |
| 741 /* |
| 742 if ( tests[testID] ) { |
| 743 var cat = tests[testID].category, catsm = cat.replace(/[
^\w]/g, "-"); |
| 744 if ( !$("#" + catsm).length ) { |
| 745 $("#main").append("<h2 id='" + catsm + "' class=
'test'><a href='?cat=" + cat +"'>" + cat + '</a><div class="bar"><div id="timeba
r" style="width:25%;"><span class="left">Est. Time: <strong id="left">
0:00</strong></span></div></div>'); |
| 746 } |
| 747 } |
| 748 */ |
| 749 |
| 750 testElems[testID] = $("<div class='test'></div>") |
| 751 .click(function(){ |
| 752 var next = jQuery(this).next().next(); |
| 753 if ( next.children().length == 0 ) return; |
| 754 var display = next.css("display"); |
| 755 next.css("display", display == 'none' ? 'block'
: 'none'); |
| 756 }); |
| 757 |
| 758 updateTestPos({curID: testID, collection: tests[testID] ? tests[
testID].name : testID, version: testVersions[testID]}, true); |
| 759 } |
| 760 })(); |
OLD | NEW |