Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1782)

Side by Side Diff: benchmarks/spinning-balls/v.js

Issue 8428002: Allow to set a time limit for spinning-balls and output the pause distribution at the end. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 var kPointRadius = 4; 50 var kPointRadius = 4;
51 var kInitialLifeForce = 100; 51 var kInitialLifeForce = 100;
52 52
53 var livePoints = void 0; 53 var livePoints = void 0;
54 var dyingPoints = void 0; 54 var dyingPoints = void 0;
55 var scene = void 0; 55 var scene = void 0;
56 var renderingStartTime = void 0; 56 var renderingStartTime = void 0;
57 var scene = void 0; 57 var scene = void 0;
58 var pausePlot = void 0; 58 var pausePlot = void 0;
59 var splayTree = void 0; 59 var splayTree = void 0;
60 var numberOfFrames = 0;
61 var sumOfSquaredPauses = 0;
62 var benchmarkStartTime = void 0;
63 var benchmarkTimeLimit = void 0;
64 var pauseDistribution = [];
60 65
61 66
62 function Point(x, y, z, payload) { 67 function Point(x, y, z, payload) {
63 this.x = x; 68 this.x = x;
64 this.y = y; 69 this.y = y;
65 this.z = z; 70 this.z = z;
66 71
67 this.next = null; 72 this.next = null;
68 this.prev = null; 73 this.prev = null;
69 this.payload = payload; 74 this.payload = payload;
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 Scene.prototype.draw = function () { 341 Scene.prototype.draw = function () {
337 this.ctx.save(); 342 this.ctx.save();
338 this.ctx.clearRect(0, 0, this.width, this.height); 343 this.ctx.clearRect(0, 0, this.width, this.height);
339 this.drawDyingPoints(); 344 this.drawDyingPoints();
340 this.ctx.restore(); 345 this.ctx.restore();
341 346
342 this.angle += Math.PI / 90.0; 347 this.angle += Math.PI / 90.0;
343 }; 348 };
344 349
345 350
351 function updateStats(pause) {
352 numberOfFrames++;
353 if (pause > 20) {
354 sumOfSquaredPauses += (pause - 20) * (pause - 20);
355 }
356 pauseDistribution[pause / 10] |= 0;
357 pauseDistribution[pause / 10]++;
358 }
359
360
361 function renderStats() {
362 var msg = document.createElement("p");
363 msg.innerHTML = "Score " +
364 Math.round(numberOfFrames * 1000 / sumOfSquaredPauses);
365 var table = document.createElement("table");
366 table.align = "center";
367 for (var i = 0; i < pauseDistribution.length; i++) {
368 if (pauseDistribution[i] > 0) {
369 var row = document.createElement("tr");
370 var time = document.createElement("td");
371 var count = document.createElement("td");
372 time.innerHTML = i*10 + "-" + (i+1)*10 + "ms";
373 count.innerHTML = " => " + pauseDistribution[i];
374 row.appendChild(time);
375 row.appendChild(count);
376 table.appendChild(row);
377 }
378 }
379 div.appendChild(msg);
380 div.appendChild(table);
381 }
382
383
346 function render() { 384 function render() {
347 if (typeof renderingStartTime === 'undefined') { 385 if (typeof renderingStartTime === 'undefined') {
348 renderingStartTime = Date.now(); 386 renderingStartTime = Date.now();
387 benchmarkStartTime = renderingStartTime;
349 } 388 }
350 389
351 ModifyPointsSet(); 390 ModifyPointsSet();
352 391
353 scene.draw(); 392 scene.draw();
354 393
355 var renderingEndTime = Date.now(); 394 var renderingEndTime = Date.now();
356 var pause = renderingEndTime - renderingStartTime; 395 var pause = renderingEndTime - renderingStartTime;
357 pausePlot.addPause(pause); 396 pausePlot.addPause(pause);
358 renderingStartTime = renderingEndTime; 397 renderingStartTime = renderingEndTime;
359 398
360 pausePlot.draw(); 399 pausePlot.draw();
361 400
401 updateStats(pause);
402
362 div.innerHTML = 403 div.innerHTML =
363 livePoints.count + "/" + dyingPoints.count + " " + 404 livePoints.count + "/" + dyingPoints.count + " " +
364 pause + "(max = " + pausePlot.maxPause + ") ms" ; 405 pause + "(max = " + pausePlot.maxPause + ") ms " +
406 numberOfFrames + " frames";
365 407
366 // Schedule next frame. 408 if (renderingEndTime < benchmarkStartTime + benchmarkTimeLimit) {
367 requestAnimationFrame(render); 409 // Schedule next frame.
410 requestAnimationFrame(render);
411 } else {
412 renderStats();
413 }
368 } 414 }
369 415
370 416
417 function renderForm() {
418 form = document.createElement("form");
419 form.setAttribute("action", "javascript:start()");
420 var label = document.createTextNode("Time limit in seconds ");
421 var input = document.createElement("input");
422 input.setAttribute("id", "timelimit");
423 input.setAttribute("value", "60");
424 var button = document.createElement("input");
425 button.setAttribute("type", "submit");
426 button.setAttribute("value", "Start");
427 form.appendChild(label);
428 form.appendChild(input);
429 form.appendChild(button);
430 document.body.appendChild(form);
431 }
432
433
371 function init() { 434 function init() {
372 livePoints = new PointsList; 435 livePoints = new PointsList;
373 dyingPoints = new PointsList; 436 dyingPoints = new PointsList;
374 437
375 splayTree = new SplayTree(); 438 splayTree = new SplayTree();
376 439
377 scene = new Scene(640, 480); 440 scene = new Scene(640, 480);
378 441
379 div = document.createElement("div"); 442 div = document.createElement("div");
380 document.body.appendChild(div); 443 document.body.appendChild(div);
381 444
382 pausePlot = new PausePlot(480, 240, 160); 445 pausePlot = new PausePlot(480, 240, 160);
383 } 446 }
384 447
448 function start() {
449 benchmarkTimeLimit = document.getElementById("timelimit").value * 1000;
450 document.body.removeChild(form);
451 init();
452 render();
453 }
385 454
386 init(); 455 renderForm();
387 render();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698