]> git.parisson.com Git - pdf.js.git/commitdiff
Replace tic & toc by console.time/timeEnd
authorJulian Viereck <julian.viereck@gmail.com>
Thu, 23 Jun 2011 21:06:33 +0000 (23:06 +0200)
committerJulian Viereck <julian.viereck@gmail.com>
Thu, 23 Jun 2011 21:33:25 +0000 (23:33 +0200)
pdf_worker.js
worker_client.js

index 86dfec2ddf52c0d5969fae0f91d3223562599b9c..fa29428c78048c7ac6531454384edb078ea3c6c6 100644 (file)
@@ -3,26 +3,27 @@
 
 "use strict";
 
-var timer = null;
-function tic() {
-  timer = Date.now();
-}
-
-function toc(msg) {
-  log(msg + ": " + (Date.now() - timer) + "ms");
-  timer = null;
-}
-
-function log() {
-  var args = Array.prototype.slice.call(arguments);
-  postMessage({
-    action: "log",
-    data: args
-  });
-}
-
+var consoleTimer = {};
 var console = {
-  log: log
+  log: function log() {
+    var args = Array.prototype.slice.call(arguments);
+    postMessage({
+      action: "log",
+      data: args
+    });
+  },
+  
+  time: function(name) {
+    consoleTimer[name] = Date.now();
+  },
+  
+  timeEnd: function(name) {
+    var time = consoleTimer[name];
+    if (time == null) {
+      throw "Unkown timer name " + name;
+    }
+    this.log("Timer:", name, Date.now() - time);
+  }
 }
 
 //
@@ -52,7 +53,7 @@ onmessage = function(event) {
   }
   // User requested to render a certain page.
   else {
-    tic();
+    console.time("compile");
 
     // Let's try to render the first page...
     var page = pdfDocument.getPage(parseInt(data));
@@ -62,9 +63,9 @@ onmessage = function(event) {
     var fonts = [];
     var gfx = new CanvasGraphics(canvas.getContext("2d"), CanvasProxy);
     page.compile(gfx, fonts);
-    toc("compiled page");
+    console.timeEnd("compile");
 
-    tic()
+    console.time("fonts");
     // Inspect fonts and translate the missing one.
     var count = fonts.length;
     for (var i = 0; i < count; i++) {
@@ -77,11 +78,11 @@ onmessage = function(event) {
       // This "builds" the font and sents it over to the main thread.
       new Font(font.name, font.file, font.properties);
     }
-    toc("fonts");
+    console.timeEnd("fonts");
 
-    tic()
+    console.time("display");
     page.display(gfx);
     canvas.flush();
-    toc("displayed page");
+    console.timeEnd("display");
   }
 }
index c1e124693e8b39bf0ce4135baaa1af16bd683149..b39374af117fb617669412d6da22c93f0eb4189b 100644 (file)
@@ -3,15 +3,23 @@
 
 "use strict";
 
+if (typeof console.time == "undefined") {
+  var consoleTimer = {};
+  console.time = function(name) {
+    consoleTimer[name] = Date.now();
+  };
+  
+  console.timeEnd = function(name) {
+    var time = consoleTimer[name];
+    if (time == null) {
+      throw "Unkown timer name " + name;
+    }
+    this.log("Timer:", name, Date.now() - time);
+  };
+}
+
 function WorkerPDFDoc(canvas) {
   var timer = null
-  function tic() {
-    timer = Date.now();
-  }
-
-  function toc(msg) {
-    console.log(msg + ": " + (Date.now() - timer) + "ms");
-  }
 
   this.ctx = canvas.getContext("2d");
   this.canvas = canvas;
@@ -203,7 +211,7 @@ function WorkerPDFDoc(canvas) {
         // rendering at the end of the event queue ensures this.
         setTimeout(function() {
           if (id == 0) {
-            tic();
+            console.time("canvas rendering");
             var ctx = this.ctx;
             ctx.save();
             ctx.fillStyle = "rgb(255, 255, 255)";
@@ -211,7 +219,7 @@ function WorkerPDFDoc(canvas) {
             ctx.restore();
           }
           renderProxyCanvas(canvasList[id], cmdQueue);
-          if (id == 0) toc("canvas rendering")
+          if (id == 0) console.timeEnd("canvas rendering")
         }, 0, this);
     }
   }