// Portions copyright 2012 Google, Inc. // Portions copyright 2011 Mozilla Foundation. All rights reserved.
// This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// The PDF-JS code in this file has been written by Mozilla. // It is available in its latest version from: // // https://github.com/mozilla/pdf.js
//////// Benchmark set-up. (c) by Google. ////////
var pdf_file = "test.pdf"; var canvas_logs = [];
var PdfJS = new BenchmarkSuite("PdfJS", [10124921], [ new Benchmark("PdfJS", false, false, 24,
runPdfJS, setupPdfJS, tearDownPdfJS, null, 4)
]);
function setupPdfJS() { // Check for Typed Arrays support, throw error if not. if (!(typeof Uint8Array != "undefined" && typeof Float64Array != "undefined" && typeof (new Uint8Array(0)).subarray != "undefined")) { throw"TypedArrayUnsupported";
}
function runPdfJS() {
PDFJS.getDocument(pdf_file).then(function(pdf) { var canvas = PdfJS_window.document.getElementById('canvas'); var context = canvas.getContext('2d'); var renderContext = {canvasContext: context};
canvas_logs.push(context.__log__);
// Cycle through all pages. function renderPages(i, j) { if (i > j) return;
context.clearRect(0, 0, canvas.width, canvas.height);
pdf.getPage(i).then(function(page) {
renderContext.viewport = page.getViewport(1);
canvas.height = renderContext.viewport.height;
canvas.width = renderContext.viewport.width;
page.render(renderContext).then(renderPages.bind(null, i + 1, j));
});
}
renderPages(1, pdf.numPages);
});
// Wait for everything to complete.
PdfJS_window.flushTimeouts();
}
function tearDownPdfJS() { // Should produce 36788 939524096 for all runs. for (var i = 0; i < canvas_logs.length; ++i) { var log_length = canvas_logs[i].length; var log_hash = hash(canvas_logs[i].join(" ")); var expected_length = 36788; var expected_hash = 939524096; if (log_length !== expected_length || log_hash !== expected_hash) { var message = "PdfJS produced incorrect output: " + "expected " + expected_length + " " + expected_hash + ", " + "got " + log_length + " " + log_hash;
console.log(message + "\n"); throw message;
}
} // Allow GC of global state. deletethis.PDFJS; deletethis.PdfJS_window;
}
function buffer(s) { var b = new ArrayBuffer(s.length); var a = new Uint8Array(b); for (var i = 0; i < s.length; ++i) a[i] = s.charCodeAt(i); return b;
}
function hash(s) { var up = Math.floor((s.length + 3) / 4); var h = 0; for (var i = 0; 4*i - 3 < s.length; i += 4) { for (var j = 0; j < 4 && i + j < s.length; ++j)
h = (h + s.charCodeAt(i + j) << (8*j)) | 0;
} return h;
}
///////// Mocks of relevant browser functionality. (c) by Google. ////////
// Every acces to window will be redirected to PdfJS_window. var PdfJS_window = Object.create(this);
function PdfJS_windowInstall(name, x) {
Object.defineProperty(PdfJS_window, name, {value: x});
}
PdfJS_windowInstall("flushTimeouts", function() { while (PdfJS_window.__timeouts__.length != 0) { var next = PdfJS_window.__timeouts__.pop(); if (typeof next === "function")
next({data: "{}"}); else
eval(next);
}
});
PdfJS_windowInstall("console", this.console ? this.console : {
log: function(s) { // To verify that the test produces the right results, // uncomment this code. /* var re = new RegExp("%d", "g"); var args = arguments; var i = 0; print(s.replace(re, function() { return args[++i] }));
*/
}
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.