diff --git a/programs/benchmark/index.html b/programs/benchmark/index.html
index 1392142b..456cdef4 100644
--- a/programs/benchmark/index.html
+++ b/programs/benchmark/index.html
@@ -11,15 +11,18 @@
Loading required files. This may take a while.
-
Benchmark results
+
Benchmark [unknown]
| Action |
Status |
- Elapsed time (ms) |
+ Time taken (ms) |
+ km/h |
+ pages/h |
+
diff --git a/programs/benchmark/js/AlignCurrentSelectionJustified.js b/programs/benchmark/js/AlignCurrentSelectionJustified.js
index b9f849c9..eb9fb162 100644
--- a/programs/benchmark/js/AlignCurrentSelectionJustified.js
+++ b/programs/benchmark/js/AlignCurrentSelectionJustified.js
@@ -51,12 +51,14 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
this.state = state;
/**
- * @param {!SharedState} sharedState
+ * @param {!OdfBenchmarkContext} context
* @return {undefined}
*/
- this.start = function(sharedState) {
+ this.start = function(context) {
+ context.recordDistanceFromCurrentSelection(state);
action.start();
- sharedState.sessionController.getDirectFormattingController().alignParagraphJustified();
+ context.sessionController.getDirectFormattingController().alignParagraphJustified();
+ action.stop();
action.complete(true);
}
}
diff --git a/programs/benchmark/js/Benchmark.js b/programs/benchmark/js/Benchmark.js
index 05a37026..e9ead23c 100644
--- a/programs/benchmark/js/Benchmark.js
+++ b/programs/benchmark/js/Benchmark.js
@@ -36,35 +36,19 @@
* @source: https://github.com/kogmbh/WebODF/
*/
-define([], function() {
+define(["OdfBenchmarkContext"], function(OdfBenchmarkContext) {
"use strict";
- /**
- * @constructor
- * @struct
- */
- function SharedState() {
- /**
- * @type {!odf.OdfCanvas}
- */
- this.odfCanvas = null;
-
- /**
- * @type {!gui.SessionController}
- */
- this.sessionController = null;
- }
-
runtime.loadClass("core.EventNotifier");
runtime.loadClass("odf.OdfCanvas");
/**
* @constructor
+ * @param {!HTMLElement} canvasElement
*/
- function Benchmark() {
+ function Benchmark(canvasElement) {
var self = this,
- canvasElement = document.getElementById("canvas"),
- sharedState = new SharedState(),
+ context = new OdfBenchmarkContext(),
events = new core.EventNotifier(["start", "complete"]),
currentActionIndex,
lastProfileAction;
@@ -79,7 +63,7 @@ define([], function() {
if (currentAction) {
lastProfileAction = currentAction.state.description;
console.profile(lastProfileAction);
- currentAction.start(sharedState);
+ currentAction.start(context);
} else {
events.emit("complete", {});
}
@@ -96,10 +80,20 @@ define([], function() {
});
events.emit("start", {});
- sharedState.odfCanvas = new odf.OdfCanvas(canvasElement);
+ context.odfCanvas = new odf.OdfCanvas(canvasElement);
currentActionIndex = -1;
executeNextAction();
};
+
+ /**
+ * @returns {!string}
+ */
+ this.getWebODFVersion = function() {
+ return (typeof webodf_version !== "undefined"
+ ? String(webodf_version)
+ : "uncompiled"
+ );
+ };
}
return Benchmark;
diff --git a/programs/benchmark/js/BenchmarkAction.js b/programs/benchmark/js/BenchmarkAction.js
index 87c39399..55255068 100644
--- a/programs/benchmark/js/BenchmarkAction.js
+++ b/programs/benchmark/js/BenchmarkAction.js
@@ -57,11 +57,14 @@ define(function() {
startedAt = new Date().getTime();
};
+ this.stop = function() {
+ state.elapsedTime = new Date().getTime() - startedAt;
+ };
+
/**
* @param {!boolean} result
*/
this.complete = function(result) {
- state.elapsedTime = new Date().getTime() - startedAt;
state.status = result;
events.emit("complete", state);
};
diff --git a/programs/benchmark/js/BoldCurrentSelection.js b/programs/benchmark/js/BoldCurrentSelection.js
index 7436d1b8..dfc43a61 100644
--- a/programs/benchmark/js/BoldCurrentSelection.js
+++ b/programs/benchmark/js/BoldCurrentSelection.js
@@ -51,13 +51,15 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
this.state = state;
/**
- * @param {!SharedState} sharedState
+ * @param {!OdfBenchmarkContext} context
*/
- this.start = function(sharedState) {
+ this.start = function(context) {
+ context.recordDistanceFromCurrentSelection(state);
action.start();
- sharedState.sessionController.getDirectFormattingController().setBold(true);
+ context.sessionController.getDirectFormattingController().setBold(true);
+ action.stop();
action.complete(true);
- }
+ };
}
return BoldCurrentSelection;
diff --git a/programs/benchmark/js/EnterEditMode.js b/programs/benchmark/js/EnterEditMode.js
index 4a2ab76e..85e3e02b 100644
--- a/programs/benchmark/js/EnterEditMode.js
+++ b/programs/benchmark/js/EnterEditMode.js
@@ -71,9 +71,9 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
this.state = state;
/**
- * @param {!SharedState} sharedState
+ * @param {!OdfBenchmarkContext} context
*/
- this.start = function(sharedState) {
+ this.start = function(context) {
var session,
sessionController,
shadowCursor,
@@ -83,7 +83,7 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
action.start();
- session = new ops.Session(sharedState.odfCanvas);
+ session = new ops.Session(context.odfCanvas);
shadowCursor = new gui.ShadowCursor(session.getOdtDocument());
sessionController = new gui.SessionController(session, localMemberId, shadowCursor, sessionControllerOptions);
sessionController.setUndoManager(undoManager);
@@ -104,8 +104,11 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
sessionController.insertLocalCursor();
sessionController.startEditing();
- sharedState.sessionController = sessionController;
+ context.session = session;
+ context.sessionController = sessionController;
+
+ action.stop();
action.complete(true);
};
}
diff --git a/programs/benchmark/js/HTMLActionResult.js b/programs/benchmark/js/HTMLActionResult.js
new file mode 100644
index 00000000..af49b58d
--- /dev/null
+++ b/programs/benchmark/js/HTMLActionResult.js
@@ -0,0 +1,108 @@
+/**
+ * @license
+ * Copyright (C) 2010-2014 KO GmbH
+ *
+ * @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.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with WebODF. If not, see .
+ * @licend
+ *
+ * @source: http://www.webodf.org/
+ * @source: https://github.com/kogmbh/WebODF/
+ */
+
+
+define(function() {
+ "use strict";
+
+ /**
+ * @constructor
+ * @param {!Object} action
+ * @param {!number} index
+ * @param {!HTMLTableElement} outputTable
+ * @param {!number} pxPerCm
+ */
+ function HTMLActionResult(action, index, outputTable, pxPerCm) {
+ var descriptionCell = document.createElement('td'),
+ statusCell = document.createElement('td'),
+ elapsedMsCell = document.createElement('td'),
+ speedCell = document.createElement('td'),
+ pagesPerHr = document.createElement('td');
+
+ function formatNumber(number) {
+ if (number > 1000000) {
+ return (number / 1000000).toFixed(2) + " mill";
+ }
+ return number.toFixed(2);
+ }
+
+ function pxPerMsToKmPerHr(pxPerMs) {
+ // Google knows!
+ // https://www.google.com.au/search?q=centimeters%20per%20millisecond%20to%20kilometers%20per%20hour
+ var cmPerSecond = (pxPerMs / pxPerCm),
+ kmsPerHr = (cmPerSecond * 36);
+ return formatNumber(kmsPerHr);
+ }
+
+ function toPagesPerMin(stepsPerMs) {
+ // http://anycount.com/WordCountBlog/how-many-words-in-one-page/
+ var pagesPerHr = (stepsPerMs / 3838) * 1000 * 60 * 60;
+ return formatNumber(pagesPerHr);
+ }
+
+ function start() {
+ statusCell.textContent = "running";
+ elapsedMsCell.textContent = "";
+ speedCell.textContent = "";
+ }
+
+ function complete(state) {
+ statusCell.textContent = state.status ? "done" : "failed";
+ elapsedMsCell.textContent = state.elapsedTime;
+ if (state.horizontalTravelPx !== undefined) {
+ speedCell.classList.add("active");
+ speedCell.textContent = pxPerMsToKmPerHr(state.horizontalTravelPx / state.elapsedTime);
+ }
+ if (state.travelledSteps !== undefined) {
+ pagesPerHr.classList.add("active");
+ pagesPerHr.textContent = toPagesPerMin(state.travelledSteps / state.elapsedTime);
+ }
+ }
+
+ function init() {
+ var tr = document.createElement('tr');
+
+ descriptionCell.className = "action";
+ statusCell.className = "status";
+ elapsedMsCell.className = "elapsed";
+ speedCell.className = "speed";
+ pagesPerHr.className = "pages";
+
+ [descriptionCell, statusCell, elapsedMsCell, speedCell, pagesPerHr].forEach(function(cell) {
+ tr.appendChild(cell);
+ });
+
+ outputTable.appendChild(tr);
+ descriptionCell.textContent = (index + 1) + ". " + action.state.description;
+
+ action.subscribe("start", start);
+ action.subscribe("complete", complete);
+ }
+ init();
+ }
+
+ return HTMLActionResult;
+ }
+);
diff --git a/programs/benchmark/js/HTMLBenchmark.js b/programs/benchmark/js/HTMLBenchmark.js
index 7d983122..b2a696a9 100644
--- a/programs/benchmark/js/HTMLBenchmark.js
+++ b/programs/benchmark/js/HTMLBenchmark.js
@@ -99,14 +99,18 @@ define([
* @constructor
*/
function HTMLBenchmark() {
- var loadingScreen = document.getElementById('loadingScreen'),
+ var loadingScreenElement = document.getElementById('loadingScreen'),
+ canvasElement = document.getElementById("canvas"),
+ benchmarkResultsElement = document.getElementById("benchmarkResults").getElementsByTagName("tbody")[0],
+ versionElement = document.getElementById("version"),
config = getConfiguration(),
- benchmark = new Benchmark(),
- renderer = new HTMLResultsRenderer(benchmark);
+ benchmark = new Benchmark(canvasElement),
+ renderer = new HTMLResultsRenderer(benchmark, benchmarkResultsElement);
+ versionElement.textContent = benchmark.getWebODFVersion();
renderer.setBackgroundColour(config.colour);
- loadingScreen.style.display = "none";
+ loadingScreenElement.style.display = "none";
benchmark.actions.push(new PreloadDocument(config.fileUrl));
benchmark.actions.push(new OpenDocument(config.fileUrl));
diff --git a/programs/benchmark/js/HTMLResultsRenderer.js b/programs/benchmark/js/HTMLResultsRenderer.js
index a8989ecb..2baba1ff 100644
--- a/programs/benchmark/js/HTMLResultsRenderer.js
+++ b/programs/benchmark/js/HTMLResultsRenderer.js
@@ -36,48 +36,21 @@
* @source: https://github.com/kogmbh/WebODF/
*/
-define(function() {
+define(["HTMLActionResult"], function(HTMLActionResult) {
"use strict";
/**
- * @param {!Benchmark} benchmark
* @constructor
+ * @param {!Benchmark} benchmark
+ * @param {!HTMLTableElement} outputTable
*/
- function HTMLResultsRenderer(benchmark) {
- var outputTable = document.getElementById("benchmarkResults");
-
- /**
- * @param {!Text} node
- * @param {!string} newValue
- */
- function setText(node, newValue) {
- node.replaceData(0, node.length, newValue);
- }
+ function HTMLResultsRenderer(benchmark, outputTable) {
+ var results = [],
+ pxPerCm;
function onStart() {
benchmark.actions.forEach(function(action, index) {
- var tr = document.createElement('tr'),
- cells = ["action", "status", "elapsed"].map(function(clazz) {
- var td = document.createElement('td'),
- text = document.createTextNode("");
- td.className = clazz;
- td.appendChild(text);
- tr.appendChild(td);
- return text;
- });
-
- outputTable.appendChild(tr);
- setText(cells[0], (index + 1) + ". " + action.state.description);
-
- action.subscribe("start", function() {
- setText(cells[1], "running");
- setText(cells[2], "");
- });
-
- action.subscribe("complete", function(state) {
- setText(cells[1], state.status ? "done" : "failed");
- setText(cells[2], state.elapsedTime);
- });
+ results.push(new HTMLActionResult(action, index, outputTable, pxPerCm));
});
}
@@ -96,6 +69,18 @@ define(function() {
};
function init() {
+ var parent,
+ testChild;
+
+ // Determine how many px per cm on the current screen
+ parent = outputTable.parentNode;
+ testChild = document.createElement("div");
+ testChild.style.width = "1cm";
+ testChild.style.height = "1cm";
+ parent.appendChild(testChild);
+ pxPerCm = testChild.getBoundingClientRect().width;
+ parent.removeChild(testChild);
+
benchmark.subscribe("start", onStart);
benchmark.subscribe("complete", onComplete);
}
diff --git a/programs/benchmark/js/InsertLetterA.js b/programs/benchmark/js/InsertLetterA.js
index c8eea5f0..3d7ccead 100644
--- a/programs/benchmark/js/InsertLetterA.js
+++ b/programs/benchmark/js/InsertLetterA.js
@@ -52,14 +52,17 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
this.state = state;
/**
- * @param {!SharedState} sharedState
+ * @param {!OdfBenchmarkContext} context
*/
- this.start = function(sharedState) {
+ this.start = function(context) {
var count;
+ context.storeCurrentPosition(state);
action.start();
for (count = 0; count < times; count += 1) {
- sharedState.sessionController.getTextController().insertText('A');
+ context.sessionController.getTextController().insertText('A');
}
+ action.stop();
+ context.recordDistanceFromPreviousPosition(state);
action.complete(true);
}
}
diff --git a/programs/benchmark/js/MoveCursorLeft.js b/programs/benchmark/js/MoveCursorLeft.js
index 1916d3ac..1c5bfbc9 100644
--- a/programs/benchmark/js/MoveCursorLeft.js
+++ b/programs/benchmark/js/MoveCursorLeft.js
@@ -52,14 +52,17 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
this.state = state;
/**
- * @param {!SharedState} sharedState
+ * @param {!OdfBenchmarkContext} context
*/
- this.start = function(sharedState) {
+ this.start = function(context) {
var count;
+ context.storeCurrentPosition(state);
action.start();
for (count = 0; count < steps; count += 1) {
- sharedState.sessionController.getSelectionController().moveCursorToLeft();
+ context.sessionController.getSelectionController().moveCursorToLeft();
}
+ action.stop();
+ context.recordDistanceFromPreviousPosition(state);
action.complete(true);
}
}
diff --git a/programs/benchmark/js/MoveCursorToEnd.js b/programs/benchmark/js/MoveCursorToEnd.js
index 18bde0dc..258e3dcd 100644
--- a/programs/benchmark/js/MoveCursorToEnd.js
+++ b/programs/benchmark/js/MoveCursorToEnd.js
@@ -51,13 +51,16 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
this.state = state;
/**
- * @param {!SharedState} sharedState
+ * @param {!OdfBenchmarkContext} context
*/
- this.start = function(sharedState) {
+ this.start = function(context) {
+ context.storeCurrentPosition(state);
action.start();
- sharedState.sessionController.getSelectionController().moveCursorToDocumentEnd();
+ context.sessionController.getSelectionController().moveCursorToDocumentEnd();
+ action.stop();
+ context.recordDistanceFromPreviousPosition(state);
action.complete(true);
- }
+ };
}
return MoveCursorToEnd;
diff --git a/programs/benchmark/js/MoveCursorToEndDirect.js b/programs/benchmark/js/MoveCursorToEndDirect.js
index ca42030f..c8d741ea 100644
--- a/programs/benchmark/js/MoveCursorToEndDirect.js
+++ b/programs/benchmark/js/MoveCursorToEndDirect.js
@@ -51,18 +51,22 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
this.state = state;
/**
- * @param {!SharedState} sharedState
+ * @param {!OdfBenchmarkContext} context
*/
- this.start = function(sharedState) {
+ this.start = function(context) {
var canvasElement,
range;
+
+ context.storeCurrentPosition(state);
action.start();
- canvasElement = sharedState.odfCanvas.getElement();
+ canvasElement = context.odfCanvas.getElement();
range = canvasElement.ownerDocument.createRange();
range.setStart(canvasElement, canvasElement.childNodes.length);
- sharedState.sessionController.getSelectionController().selectRange(range, true, 1);
+ context.sessionController.getSelectionController().selectRange(range, true, 1);
+ action.stop();
+ context.recordDistanceFromPreviousPosition(state);
action.complete(true);
}
}
diff --git a/programs/benchmark/js/MoveCursorToStart.js b/programs/benchmark/js/MoveCursorToStart.js
index 0794a488..719914a0 100644
--- a/programs/benchmark/js/MoveCursorToStart.js
+++ b/programs/benchmark/js/MoveCursorToStart.js
@@ -39,11 +39,14 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
this.state = state;
/**
- * @param {!SharedState} sharedState
+ * @param {!OdfBenchmarkContext} context
*/
- this.start = function(sharedState) {
+ this.start = function(context) {
+ context.storeCurrentPosition(state);
action.start();
- sharedState.sessionController.getSelectionController().moveCursorToDocumentStart();
+ context.sessionController.getSelectionController().moveCursorToDocumentStart();
+ action.stop();
+ context.recordDistanceFromPreviousPosition(state);
action.complete(true);
}
}
diff --git a/programs/benchmark/js/OdfBenchmarkContext.js b/programs/benchmark/js/OdfBenchmarkContext.js
new file mode 100644
index 00000000..3db99107
--- /dev/null
+++ b/programs/benchmark/js/OdfBenchmarkContext.js
@@ -0,0 +1,139 @@
+/**
+ * @license
+ * Copyright (C) 2010-2014 KO GmbH
+ *
+ * @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.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with WebODF. If not, see .
+ * @licend
+ *
+ * @source: http://www.webodf.org/
+ * @source: https://github.com/kogmbh/WebODF/
+ */
+
+define(["RangeCalculator"], function(RangeCalculator) {
+ /**
+ * @constructor
+ */
+ function OdfBenchmarkContext() {
+ var self = this,
+ rangeCalculator = new RangeCalculator();
+
+ /**
+ * @return {boolean}
+ */
+ function initialized() {
+ return Boolean(self.session && self.sessionController);
+ }
+
+ /**
+ * @param {!number} length
+ * @return {!number}
+ */
+ function measureSelectionLength(length) {
+ var odtDocument = self.session.getOdtDocument(),
+ position = odtDocument.getCursorPosition(self.sessionController.getInputMemberId());
+
+ return rangeCalculator.measureTraversedDistance(odtDocument.convertCursorToDomRange(position, length));
+ }
+
+ /**
+ * @return {!number}
+ */
+ function measureCurrentSelection() {
+ var range = self.session.getOdtDocument().getCursor(self.sessionController.getInputMemberId()).getSelectedRange();
+ return rangeCalculator.measureTraversedDistance(range);
+ }
+
+ /**
+ * @type {?odf.OdfCanvas}
+ */
+ this.odfCanvas = null;
+
+ /**
+ * @type {?ops.Session}
+ */
+ this.session = null;
+
+ /**
+ * @type {?gui.SessionController}
+ */
+ this.sessionController = null;
+
+ /**
+ * Calculate the traveled distance from the supplied length in cursor steps
+ * @param {!Object} state
+ * @param {!number} length
+ * @return {undefined}
+ */
+ this.recordDistanceFromLength = function(state, length) {
+ if (initialized()) {
+ state.travelledSteps = Math.abs(length);
+ state.horizontalTravelPx = measureSelectionLength(length);
+ }
+ };
+
+ /**
+ * Store the current cursor position onto the provided state
+ * @param {!Object} state
+ * @return {undefined}
+ */
+ this.storeCurrentPosition = function(state) {
+ var odtDocument;
+
+ if (initialized()) {
+ odtDocument = self.session.getOdtDocument();
+ state.initialCursorPosition = odtDocument.getCursorPosition(self.sessionController.getInputMemberId());
+ }
+ };
+
+ /**
+ * Calculate the traveled distance from the previously recorded position
+ * @param {!Object} state
+ * @return {undefined}
+ */
+ this.recordDistanceFromPreviousPosition = function(state) {
+ var odtDocument,
+ finalCursorPosition;
+
+ if (initialized()) {
+ odtDocument = self.session.getOdtDocument();
+ runtime.assert(state.initialCursorPosition !== undefined, "Initial cursor position should first be saved with context.storeCurrentPosition");
+ finalCursorPosition = odtDocument.getCursorPosition(self.sessionController.getInputMemberId());
+ state.travelledSteps = Math.abs(state.initialCursorPosition - finalCursorPosition);
+ state.horizontalTravelPx = measureSelectionLength(state.initialCursorPosition - finalCursorPosition)
+ }
+ };
+
+ /**
+ * Calculate the traveled distance from the current selection
+ * @param {!Object} state
+ * @return {undefined}
+ */
+ this.recordDistanceFromCurrentSelection = function(state) {
+ var odtDocument,
+ selection;
+
+ if (initialized()) {
+ odtDocument = self.session.getOdtDocument();
+ selection = odtDocument.getCursorSelection(self.sessionController.getInputMemberId());
+ state.travelledSteps = Math.abs(selection.length);
+ state.horizontalTravelPx = measureCurrentSelection();
+ }
+ };
+ }
+
+ return OdfBenchmarkContext;
+});
\ No newline at end of file
diff --git a/programs/benchmark/js/OpenDocument.js b/programs/benchmark/js/OpenDocument.js
index 5a17279b..e4f2bf9e 100644
--- a/programs/benchmark/js/OpenDocument.js
+++ b/programs/benchmark/js/OpenDocument.js
@@ -49,6 +49,7 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
action = new BenchmarkAction(state);
function onDocumentLoaded() {
+ action.stop();
action.complete(true);
}
@@ -56,12 +57,12 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
this.state = state;
/**
- * @param {!SharedState} sharedState
+ * @param {!OdfBenchmarkContext} context
*/
- this.start = function(sharedState) {
+ this.start = function(context) {
action.start();
- sharedState.odfCanvas.addListener("statereadychange", onDocumentLoaded);
- sharedState.odfCanvas.load(docUrl);
+ context.odfCanvas.addListener("statereadychange", onDocumentLoaded);
+ context.odfCanvas.load(docUrl);
};
}
diff --git a/programs/benchmark/js/PreloadDocument.js b/programs/benchmark/js/PreloadDocument.js
index b4da8a22..5953f6bb 100644
--- a/programs/benchmark/js/PreloadDocument.js
+++ b/programs/benchmark/js/PreloadDocument.js
@@ -49,6 +49,7 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
action = new BenchmarkAction(state);
function onDocumentDownloaded() {
+ action.stop();
action.complete(true);
}
@@ -56,9 +57,9 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
this.state = state;
/**
- * @param {!SharedState} sharedState
+ * @param {!OdfBenchmarkContext} context
*/
- this.start = function(sharedState) {
+ this.start = function(context) {
action.start();
runtime.readFile(docUrl, 'binary', onDocumentDownloaded);
};
diff --git a/programs/benchmark/js/RangeCalculator.js b/programs/benchmark/js/RangeCalculator.js
new file mode 100644
index 00000000..614a6b3e
--- /dev/null
+++ b/programs/benchmark/js/RangeCalculator.js
@@ -0,0 +1,77 @@
+/**
+ * @license
+ * Copyright (C) 2010-2014 KO GmbH
+ *
+ * @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.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with WebODF. If not, see .
+ * @licend
+ *
+ * @source: http://www.webodf.org/
+ * @source: https://github.com/kogmbh/WebODF/
+ */
+
+define([], function() {
+
+ runtime.loadClass("odf.OdfUtils");
+
+ /**
+ * @constructor
+ */
+ function RangeCalculator() {
+ var odfUtils = new odf.OdfUtils(),
+ textRange = document.createRange(),
+ TEXT_NODE = Node.TEXT_NODE;
+
+ /**
+ * Calculate the amount of horizontal movement experienced while traversing
+ * the supplied range.
+ * @param {!Range} range
+ * @return {!number}
+ */
+ this.measureTraversedDistance = function (range) {
+ var textElements = odfUtils.getTextElements(range, true, false),
+ horizontalDistance = 0;
+
+ textElements.forEach(function(node) {
+ var clientRects,
+ i,
+ rect;
+
+ if (node.nodeType === TEXT_NODE) {
+ textRange.selectNodeContents(node);
+ if (range.startContainer === node) {
+ textRange.setStart(range.startContainer, range.startOffset);
+ }
+ if (range.endContainer === node) {
+ range.setEnd(range.endContainer, range.endOffset);
+ }
+ clientRects = textRange.getClientRects();
+ } else {
+ clientRects = node.getClientRects();
+ }
+ for (i = 0; i < clientRects.length; i += 1) {
+ rect = clientRects[i];
+ horizontalDistance += rect.width;
+ }
+ });
+
+ return horizontalDistance;
+ };
+ }
+
+ return RangeCalculator;
+
+});
\ No newline at end of file
diff --git a/programs/benchmark/js/RemoveCurrentSelection.js b/programs/benchmark/js/RemoveCurrentSelection.js
index 815b49d4..cdec6925 100644
--- a/programs/benchmark/js/RemoveCurrentSelection.js
+++ b/programs/benchmark/js/RemoveCurrentSelection.js
@@ -51,11 +51,13 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
this.state = state;
/**
- * @param {!SharedState} sharedState
+ * @param {!OdfBenchmarkContext} context
*/
- this.start = function(sharedState) {
+ this.start = function(context) {
+ context.recordDistanceFromCurrentSelection(state);
action.start();
- sharedState.sessionController.getTextController().removeCurrentSelection();
+ context.sessionController.getTextController().removeCurrentSelection();
+ action.stop();
action.complete(true);
}
}
diff --git a/programs/benchmark/js/RemovePositions.js b/programs/benchmark/js/RemovePositions.js
index eda31735..5a3f2b3f 100644
--- a/programs/benchmark/js/RemovePositions.js
+++ b/programs/benchmark/js/RemovePositions.js
@@ -53,18 +53,20 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
this.state = state;
/**
- * @param {!SharedState} sharedState
+ * @param {!OdfBenchmarkContext} context
*/
- this.start = function(sharedState) {
+ this.start = function(context) {
var count;
+ context.recordDistanceFromLength(state, useBackspace ? -times : times);
action.start();
for (count = 0; count < times; count += 1) {
if (useBackspace) {
- sharedState.sessionController.getTextController().removeTextByBackspaceKey();
+ context.sessionController.getTextController().removeTextByBackspaceKey();
} else {
- sharedState.sessionController.getTextController().removeTextByDeleteKey();
+ context.sessionController.getTextController().removeTextByDeleteKey();
}
}
+ action.stop();
action.complete(true);
}
}
diff --git a/programs/benchmark/js/SelectEntireDocument.js b/programs/benchmark/js/SelectEntireDocument.js
index 061746df..0435ef1d 100644
--- a/programs/benchmark/js/SelectEntireDocument.js
+++ b/programs/benchmark/js/SelectEntireDocument.js
@@ -51,13 +51,15 @@ define(["BenchmarkAction"], function(BenchmarkAction) {
this.state = state;
/**
- * @param {!SharedState} sharedState
+ * @param {!OdfBenchmarkContext} context
*/
- this.start = function(sharedState) {
+ this.start = function(context) {
action.start();
- sharedState.sessionController.getSelectionController().extendSelectionToEntireDocument();
+ context.sessionController.getSelectionController().extendSelectionToEntireDocument();
+ action.stop();
+ context.recordDistanceFromCurrentSelection(state);
action.complete(true);
- }
+ };
}
return SelectEntireDocument;
diff --git a/programs/benchmark/runner.css b/programs/benchmark/runner.css
index 1f8dfc21..dd355986 100644
--- a/programs/benchmark/runner.css
+++ b/programs/benchmark/runner.css
@@ -12,20 +12,75 @@ body {
max-width: 100%;
/*width: 400px;*/
float: left;
- background-color: #70a186;
+ background-color: #49A34B;
padding: 0 10px;
}
+#benchmarkView h1 {
+ text-align: center;
+}
+
#documentView {
min-height: 100%;
overflow: auto;
}
+#benchmarkResults {
+ border-collapse: collapse;
+ margin-bottom: 10px;
+}
+
+#benchmarkResults td {
+ padding-top: 5px;
+ padding-bottom: 5px;
+}
+
+#benchmarkResults thead {
+ font-weight: bold;
+ font-size: small;
+}
+
+#benchmarkResults thead td {
+ text-align: center;
+}
+
+#benchmarkResults thead td:not(:last-of-type) {
+ border-right: 1px solid white;
+}
+
+#benchmarkResults tbody td {
+ border-right: 1px solid white;
+}
+
+#benchmarkResults tbody td:first-of-type {
+ border-left: 1px solid white;
+}
+
+#benchmarkResults tbody tr {
+ border-top: 1px solid white;
+}
+
+#benchmarkResults tbody tr:hover td {
+ background-color: #5AB953;
+}
+
+#benchmarkResults tbody tr:nth-child(2n+0) {
+ background-color: #E6FFBF;
+}
+
+#benchmarkResults tbody tr:nth-child(2n+1) {
+ background-color: #BEEE9E;
+}
+
#benchmarkResults .status {
display: none;
}
-#benchmarkResults .elapsed {
+#benchmarkResults tbody .elapsed,
+#benchmarkResults tbody .speed,
+#benchmarkResults tbody .pages
+{
+ padding-left: 1em;
text-align: right;
}
diff --git a/programs/benchmark/src-index.html b/programs/benchmark/src-index.html
index a9ccf3b9..63185b45 100644
--- a/programs/benchmark/src-index.html
+++ b/programs/benchmark/src-index.html
@@ -31,15 +31,18 @@
Loading required files. This may take a while.
-
Benchmark results
+
Benchmark [unknown]
| Action |
Status |
- Elapsed time (ms) |
+ Time taken (ms) |
+ km/h |
+ pages/h |
+