Browse Source

Display render time

probably not very accurate thanks to eval()...
v1.x
Tj Holowaychuk 14 years ago
parent
commit
e692a97ede
  1. 6
      test/public/app.js
  2. 5
      test/server.js

6
test/public/app.js

@ -47,8 +47,10 @@ function runTests() {
} }
function runTest(name, canvas, dest) { function runTest(name, canvas, dest) {
var fn = tests[name]; var fn = tests[name]
, start = new Date;
fn(canvas.getContext('2d')); fn(canvas.getContext('2d'));
canvas.title += ' (rendered in ' + (new Date - start) + 'ms)';
renderOnServer(name, canvas, function(res){ renderOnServer(name, canvas, function(res){
if (res.error) { if (res.error) {
var p = create('p'); var p = create('p');
@ -57,7 +59,7 @@ function runTest(name, canvas, dest) {
} else if (res.data) { } else if (res.data) {
var img = create('image'); var img = create('image');
img.src = res.data; img.src = res.data;
img.alt = img.title = name; img.alt = img.title = name + ' (rendered in ' + res.duration + 'ms)';
dest.appendChild(img); dest.appendChild(img);
} }
}); });

5
test/server.js

@ -35,9 +35,10 @@ app.post('/render', function(req, res, next){
, width = req.body.width , width = req.body.width
, height = req.body.height , height = req.body.height
, canvas = new Canvas(width, height) , canvas = new Canvas(width, height)
, ctx = canvas.getContext('2d'); , ctx = canvas.getContext('2d')
, start = new Date;
fn(ctx); fn(ctx);
res.send({ data: canvas.toDataURL() }); res.send({ data: canvas.toDataURL(), duration: new Date - start });
}); });
app.listen(3000); app.listen(3000);

Loading…
Cancel
Save