Files
WebODF/programs/benchmark/js/HTMLBenchmark.js
T

132 lines
5.0 KiB
JavaScript
Raw Normal View History

2013-11-06 14:31:44 +11:00
/**
* Copyright (C) 2013 KO GmbH <copyright@kogmbh.com>
*
* @licstart
* This file is part of WebODF.
*
* WebODF is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License (GNU AGPL)
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* WebODF 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 Affero General Public License for more details.
2013-11-06 14:31:44 +11:00
*
* You should have received a copy of the GNU Affero General Public License
* along with WebODF. If not, see <http://www.gnu.org/licenses/>.
2013-11-06 14:31:44 +11:00
* @licend
*
2013-11-06 14:31:44 +11:00
* @source: http://www.webodf.org/
* @source: https://github.com/kogmbh/WebODF/
*/
2015-02-19 22:05:32 +01:00
/*global define, document, window, webodf*/
define([
2013-11-06 14:31:44 +11:00
"Benchmark",
"HTMLResultsRenderer",
"OpenDocument",
2013-11-06 14:31:44 +11:00
"EnterEditMode",
"MoveCursorToEndDirect",
"InsertLetterA",
2013-12-13 21:42:58 +11:00
"RemovePositions",
"MoveCursorLeft",
2013-11-06 14:31:44 +11:00
"SelectEntireDocument",
"RemoveCurrentSelection",
"PreloadDocument",
"BoldCurrentSelection",
2014-01-31 16:29:12 +11:00
"AlignCurrentSelectionJustified",
"MoveCursorToEnd",
"MoveCursorToStart"
2013-11-06 14:31:44 +11:00
], function (Benchmark, HTMLResultsRenderer,
2013-12-13 21:42:58 +11:00
OpenDocument, EnterEditMode, MoveCursorToEndDirect,InsertLetterA, RemovePositions, MoveCursorLeft,
2014-01-31 16:29:12 +11:00
SelectEntireDocument, RemoveCurrentSelection, PreloadDocument, BoldCurrentSelection,
AlignCurrentSelectionJustified, MoveCursorToEnd, MoveCursorToStart) {
2013-11-06 14:31:44 +11:00
"use strict";
/**
* Convert url query parameters into an Object
* Source: http://stackoverflow.com/a/2880929
* @return {!Object.<!string, !string>}
*/
function getQueryParams() {
2015-02-19 22:05:32 +01:00
/*jslint regexp: true*/
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1),
urlParams = {};
2015-02-19 22:05:32 +01:00
/*jslint regexp: false*/
2015-02-19 22:05:32 +01:00
match = search.exec(query);
while (match) {
urlParams[decode(match[1])] = decode(match[2]);
2015-02-19 22:05:32 +01:00
match = search.exec(query);
}
return urlParams;
}
/**
* Extract supported benchmark options from the url query parameters
2015-05-31 13:27:31 +02:00
* @return {!{fileUrl: !string, includeSlow: !boolean, colour: (string|undefined)}}
*/
function getConfiguration() {
var params = getQueryParams();
return {
/** Test document to load. Relative or absolute urls are supported */
fileUrl: params.fileUrl || "100pages.odt",
/** Include known slow actions in the benchmark. These can take 10 or more minutes each on large docs */
includeSlow: params.includeSlow || false,
/** Background colour of the benchmark results. Useful for distinguishing different benchmark versions */
colour: params.colour
};
}
2013-11-21 01:27:12 +11:00
/**
* @constructor
*/
function HTMLBenchmark() {
2014-02-28 01:33:32 +11:00
var loadingScreenElement = document.getElementById('loadingScreen'),
canvasElement = document.getElementById("canvas"),
2014-02-28 01:33:32 +11:00
benchmarkResultsElement = document.getElementById("benchmarkResults").getElementsByTagName("tbody")[0],
versionElement = document.getElementById("version"),
config = getConfiguration(),
benchmark = new Benchmark(canvasElement),
2014-02-28 01:33:32 +11:00
renderer = new HTMLResultsRenderer(benchmark, benchmarkResultsElement);
2013-11-06 14:31:44 +11:00
versionElement.textContent = webodf.Version;
renderer.setBackgroundColour(config.colour);
2013-11-06 14:31:44 +11:00
2014-02-28 01:33:32 +11:00
loadingScreenElement.style.display = "none";
2013-11-06 14:31:44 +11:00
benchmark.actions.push(new PreloadDocument(config.fileUrl));
benchmark.actions.push(new OpenDocument(config.fileUrl));
benchmark.actions.push(new EnterEditMode());
benchmark.actions.push(new MoveCursorToEnd());
benchmark.actions.push(new MoveCursorToStart());
benchmark.actions.push(new InsertLetterA(100));
benchmark.actions.push(new RemovePositions(100, true));
benchmark.actions.push(new MoveCursorToEndDirect());
2013-12-13 21:42:58 +11:00
benchmark.actions.push(new InsertLetterA(1));
benchmark.actions.push(new InsertLetterA(100));
benchmark.actions.push(new RemovePositions(1, true));
benchmark.actions.push(new MoveCursorLeft(1));
benchmark.actions.push(new MoveCursorLeft(100));
benchmark.actions.push(new RemovePositions(1, false));
benchmark.actions.push(new RemovePositions(100, true));
benchmark.actions.push(new SelectEntireDocument());
2013-12-13 21:42:58 +11:00
benchmark.actions.push(new BoldCurrentSelection());
benchmark.actions.push(new AlignCurrentSelectionJustified());
benchmark.actions.push(new RemoveCurrentSelection());
this.start = benchmark.start;
}
return HTMLBenchmark;
2013-11-06 14:31:44 +11:00
});