Commit 41ae1951 authored by rniwa@webkit.org's avatar rniwa@webkit.org

Add a not completely unrealistic DOM Benchmark

https://bugs.webkit.org/show_bug.cgi?id=121361

Reviewed by Filip Pizlo.

Add a DOM benchmark based on TodoMVC for vanilla JS, Ember.js, Backbone.js, and jQuery.
We'll add more frameworks and demo apps as we go.

* DoYouEvenBench: Added.
* DoYouEvenBench/benchmark.html: Added.
* DoYouEvenBench/benchmark.js: Added.
(SimplePromise): 
(SimplePromise.prototype.then):
(SimplePromise.prototype.resolve.else):
(SimplePromise.prototype.resolve):
(BenchmarkRunner.suite):
(BenchmarkRunner.waitForElement.resolveIfReady):
(BenchmarkRunner.waitForElement):
(BenchmarkRunner._removeFrame):
(BenchmarkRunner._appendFrame):
(BenchmarkRunner._waitAndWarmUp.Fibonacci):
(BenchmarkRunner._testName):
(BenchmarkRunner._testItemId):
(BenchmarkRunner.listSuites.button.onclick):
(BenchmarkRunner.listSuites.callNextStep):
(BenchmarkRunner.listSuites):
(BenchmarkState):
(BenchmarkState.prototype.currentSuite):
(BenchmarkState.prototype.currentTest):
(BenchmarkState.prototype.next):
(BenchmarkState.prototype.isFirstTest):
(BenchmarkState.prototype.prepareCurrentSuite.frame.onload):
(BenchmarkRunner.step):
(BenchmarkRunner._runTestAndRecordResults):
(BenchmarkRunner._finalize):
* DoYouEvenBench/todomvc: Added.
* DoYouEvenBench/todomvc/architecture-examples: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower.json: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/backbone: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/backbone.localStorage: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/backbone.localStorage/backbone.localStorage.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/backbone/backbone.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/jquery: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/jquery/jquery.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/todomvc-common: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/todomvc-common/base.css: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/todomvc-common/base.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/todomvc-common/bg.png: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/underscore: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/underscore/underscore.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/index.html: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/app.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/collections: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/collections/todos.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/models: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/models/todo.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/routers: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/routers/router.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/views: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/views/app-view.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/views/todo-view.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/readme.md: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower.json: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/ember: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/ember-localstorage-adapter: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/ember-localstorage-adapter/localstorage_adapter.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/ember/ember.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/handlebars: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/handlebars/handlebars.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/jquery: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/jquery/jquery.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/todomvc-common: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/todomvc-common/base.css: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/todomvc-common/base.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/todomvc-common/bg.png: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/index.html: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/app.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/controllers: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/controllers/todo_controller.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/controllers/todos_controller.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/libs: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/libs/ember-data.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/models: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/models/store.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/models/todo.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/views: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/views/edit_todo_view.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/readme.md: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/test.html: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower.json: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/handlebars: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/handlebars/handlebars.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/jquery: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/jquery/jquery.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/todomvc-common: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/todomvc-common/base.css: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/todomvc-common/base.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/todomvc-common/bg.png: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/css: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/css/app.css: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/index.html: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/js: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/js/app.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/readme.md: Added.
* DoYouEvenBench/todomvc/license.md: Added.
* DoYouEvenBench/todomvc/readme.md: Added.
* DoYouEvenBench/todomvc/vanilla-examples: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/bower.json: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/bower_components: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/bower_components/todomvc-common: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/bower_components/todomvc-common/base.css: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/bower_components/todomvc-common/base.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/bower_components/todomvc-common/bg.png: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/index.html: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js/app.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js/controller.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js/helpers.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js/model.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js/store.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js/view.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/readme.md: Added.
* Skipped:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156073 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f3a210d5
2013-09-17 Ryosuke Niwa <rniwa@webkit.org>
Add a not completely unrealistic DOM Benchmark
https://bugs.webkit.org/show_bug.cgi?id=121361
Reviewed by Filip Pizlo.
Add a DOM benchmark based on TodoMVC for vanilla JS, Ember.js, Backbone.js, and jQuery.
We'll add more frameworks and demo apps as we go.
* DoYouEvenBench: Added.
* DoYouEvenBench/benchmark.html: Added.
* DoYouEvenBench/benchmark.js: Added.
(SimplePromise):
(SimplePromise.prototype.then):
(SimplePromise.prototype.resolve.else):
(SimplePromise.prototype.resolve):
(BenchmarkRunner.suite):
(BenchmarkRunner.waitForElement.resolveIfReady):
(BenchmarkRunner.waitForElement):
(BenchmarkRunner._removeFrame):
(BenchmarkRunner._appendFrame):
(BenchmarkRunner._waitAndWarmUp.Fibonacci):
(BenchmarkRunner._testName):
(BenchmarkRunner._testItemId):
(BenchmarkRunner.listSuites.button.onclick):
(BenchmarkRunner.listSuites.callNextStep):
(BenchmarkRunner.listSuites):
(BenchmarkState):
(BenchmarkState.prototype.currentSuite):
(BenchmarkState.prototype.currentTest):
(BenchmarkState.prototype.next):
(BenchmarkState.prototype.isFirstTest):
(BenchmarkState.prototype.prepareCurrentSuite.frame.onload):
(BenchmarkRunner.step):
(BenchmarkRunner._runTestAndRecordResults):
(BenchmarkRunner._finalize):
* DoYouEvenBench/todomvc: Added.
* DoYouEvenBench/todomvc/architecture-examples: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower.json: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/backbone: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/backbone.localStorage: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/backbone.localStorage/backbone.localStorage.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/backbone/backbone.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/jquery: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/jquery/jquery.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/todomvc-common: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/todomvc-common/base.css: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/todomvc-common/base.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/todomvc-common/bg.png: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/underscore: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/bower_components/underscore/underscore.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/index.html: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/app.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/collections: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/collections/todos.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/models: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/models/todo.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/routers: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/routers/router.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/views: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/views/app-view.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/js/views/todo-view.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/backbone/readme.md: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower.json: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/ember: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/ember-localstorage-adapter: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/ember-localstorage-adapter/localstorage_adapter.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/ember/ember.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/handlebars: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/handlebars/handlebars.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/jquery: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/jquery/jquery.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/todomvc-common: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/todomvc-common/base.css: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/todomvc-common/base.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/bower_components/todomvc-common/bg.png: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/index.html: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/app.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/controllers: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/controllers/todo_controller.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/controllers/todos_controller.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/libs: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/libs/ember-data.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/models: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/models/store.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/models/todo.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/views: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/js/views/edit_todo_view.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/readme.md: Added.
* DoYouEvenBench/todomvc/architecture-examples/emberjs/test.html: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower.json: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/handlebars: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/handlebars/handlebars.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/jquery: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/jquery/jquery.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/todomvc-common: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/todomvc-common/base.css: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/todomvc-common/base.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/bower_components/todomvc-common/bg.png: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/css: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/css/app.css: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/index.html: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/js: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/js/app.js: Added.
* DoYouEvenBench/todomvc/architecture-examples/jquery/readme.md: Added.
* DoYouEvenBench/todomvc/license.md: Added.
* DoYouEvenBench/todomvc/readme.md: Added.
* DoYouEvenBench/todomvc/vanilla-examples: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/bower.json: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/bower_components: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/bower_components/todomvc-common: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/bower_components/todomvc-common/base.css: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/bower_components/todomvc-common/base.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/bower_components/todomvc-common/bg.png: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/index.html: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js/app.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js/controller.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js/helpers.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js/model.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js/store.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/js/view.js: Added.
* DoYouEvenBench/todomvc/vanilla-examples/vanillajs/readme.md: Added.
* Skipped:
2013-09-04 Filip Pizlo <fpizlo@apple.com>
Introduce a version of SunSpider that runs for a really long time (about 1 sec on my machine)
......
<!DOCTYPE html>
<html>
<head>
<title>Not Completely Unrealistic DOM Benchmark</title>
<script src="benchmark.js"></script>
<script>
var numberOfItemsToAdd = 100;
BenchmarkRunner.suite({
name: 'VanillaJS/TodoMVC',
url: 'todomvc/vanilla-examples/vanillajs/index.html',
prepare: function (contentWindow, contentDocument) {
return BenchmarkRunner.waitForElement('#new-todo').then(function (element) {
element.focus();
return element;
});
},
tests: [
['Adding' + numberOfItemsToAdd + 'Items', function (newTodo, contentWindow, contentDocument) {
var todoController = contentWindow.todo.controller;
for (var i = 0; i < numberOfItemsToAdd; i++) {
newTodo.value = 'Something to do ' + i;
todoController.addItem({keyCode: todoController.ENTER_KEY, target: newTodo});
}
}],
['CompletingAllItems', function (newTodo, contentWindow, contentDocument) {
var checkboxes = contentDocument.querySelectorAll('.toggle');
for (var i = 0; i < checkboxes.length; i++)
checkboxes[i].click();
}],
['DeletingAllItems', function (newTodo, contentWindow, contentDocument) {
var deleteButtons = contentDocument.querySelectorAll('.destroy');
for (var i = 0; i < deleteButtons.length; i++)
deleteButtons[i].click();
}],
]
});
BenchmarkRunner.suite({
name: 'EmberJS/TodoMVC',
url: 'todomvc/architecture-examples/emberjs/index.html',
prepare: function (contentWindow, contentDocument) {
contentWindow.Todos.Store = contentWindow.DS.Store.extend({
revision: 12,
adapter: 'Todos.LSAdapter',
commit: function () { }
});
return BenchmarkRunner.waitForElement('#new-todo').then(function (element) {
element.focus();
return {
views: contentWindow.Ember.View.views,
emberRun: contentWindow.Ember.run,
}
});
},
tests: [
['Adding' + numberOfItemsToAdd + 'Items', function (params) {
for (var i = 0; i < numberOfItemsToAdd; i++) {
params.emberRun(function () { params.views["new-todo"].set('value', 'Something to do' + i); });
params.emberRun(function () { params.views["new-todo"].insertNewline(document.createEvent('Event')); });
}
}],
['CompletingAllItems', function (params, contentWindow, contentDocument) {
var checkboxes = contentDocument.querySelectorAll('.ember-checkbox');
for (var i = 0; i < checkboxes.length; i++) {
var view = params.views[checkboxes[i].id];
params.emberRun(function () { view.set('checked', true); });
}
}],
['DeletingItems', function (params, contentWindow, contentDocument) {
var deleteButtons = contentDocument.querySelectorAll('.destroy');
for (var i = 0; i < deleteButtons.length; i++)
params.emberRun(function () { deleteButtons[i].click(); });
}],
]
});
BenchmarkRunner.suite({
name: 'BackboneJS/TodoMVC',
url: 'todomvc/architecture-examples/backbone/index.html',
prepare: function (contentWindow, contentDocument) {
contentWindow.Backbone.sync = function () {}
return BenchmarkRunner.waitForElement('#new-todo').then(function (element) {
element.focus();
return element;
});
},
tests: [
['Adding' + numberOfItemsToAdd + 'Items', function (newTodo, contentWindow, contentDocument) {
var appView = contentWindow.appView;
var fakeEvent = {which: contentWindow.ENTER_KEY};
for (var i = 0; i < numberOfItemsToAdd; i++) {
newTodo.value = 'Something to do ' + i;
appView.createOnEnter(fakeEvent);
}
}],
['CompletingAllItems', function (newTodo, contentWindow, contentDocument) {
var checkboxes = contentDocument.querySelectorAll('.toggle');
for (var i = 0; i < checkboxes.length; i++)
checkboxes[i].click();
}],
['DeletingAllItems', function (newTodo, contentWindow, contentDocument) {
var deleteButtons = contentDocument.querySelectorAll('.destroy');
for (var i = 0; i < deleteButtons.length; i++)
deleteButtons[i].click();
}],
]
});
BenchmarkRunner.suite({
name: 'jQuery/TodoMVC',
url: 'todomvc/architecture-examples/jquery/index.html',
prepare: function (contentWindow, contentDocument) {
var storage = [];
return BenchmarkRunner.waitForElement('#new-todo').then(function (element) {
element.focus();
return element;
});
},
tests: [
['Adding' + numberOfItemsToAdd + 'Items', function (newTodo, contentWindow, contentDocument) {
var app = contentWindow.app;
var fakeEvent = {which: app.ENTER_KEY};
for (var i = 0; i < numberOfItemsToAdd; i++) {
newTodo.value = 'Something to do ' + i;
app.create.call(newTodo, fakeEvent);
}
}],
['CompletingAllItems', function (newTodo, contentWindow, contentDocument) {
var app = contentWindow.app;
var checkboxes = contentDocument.querySelectorAll('.toggle');
for (var i = 0; i < checkboxes.length; i++)
app.toggle.call(checkboxes[i]);
}],
['DeletingAllItems', function (newTodo, contentWindow, contentDocument) {
var app = contentWindow.app;
var deleteButtons = contentDocument.querySelectorAll('.destroy');
for (var i = 0; i < deleteButtons.length; i++)
app.destroy.call(deleteButtons[i]);
}],
]
});
</script>
</head>
<body>
<p></p>
</body>
</html>
// FIXME: Use the real promise if available.
// FIXME: Make sure this interface is compatible with the real Promise.
function SimplePromise() {
this._chainedPromise = null;
this._callback = null;
}
SimplePromise.prototype.then = function (callback) {
if (this._callback)
throw "SimplePromise doesn't support multiple calls to then";
this._callback = callback;
this._chainedPromise = new SimplePromise;
if (this._resolved)
this.resolve(this._resolvedValue);
return this._chainedPromise;
}
SimplePromise.prototype.resolve = function (value) {
if (!this._callback) {
this._resolved = true;
this._resolvedValue = value;
return;
}
var result = this._callback(value);
if (result instanceof SimplePromise) {
var chainedPromise = this._chainedPromise;
result.then(function (result) { chainedPromise.resolve(result); });
} else
this._chainedPromise.resolve(result);
}
var BenchmarkRunner = {_suites: [], _prepareReturnValue: null, _measuredValues: {}};
BenchmarkRunner.suite = function (suite) {
var self = BenchmarkRunner;
self._suites.push(suite);
}
BenchmarkRunner.waitForElement = function (selector) {
var self = BenchmarkRunner;
var promise = new SimplePromise;
var contentDocument = self._frame.contentDocument;
function resolveIfReady() {
var element = contentDocument.querySelector(selector);
if (element)
return promise.resolve(element);
setTimeout(resolveIfReady, 50);
}
resolveIfReady();
return promise;
}
BenchmarkRunner._removeFrame = function () {
var self = BenchmarkRunner;
if (self._frame) {
self._frame.parentNode.removeChild(self._frame);
self._frame = null;
}
}
BenchmarkRunner._appendFrame = function (src) {
var self = BenchmarkRunner;
var frame = document.createElement('iframe');
document.body.appendChild(frame);
self._frame = frame;
return frame;
}
BenchmarkRunner._waitAndWarmUp = function () {
var startTime = Date.now();
function Fibonacci(n) {
if (Date.now() - startTime > 100)
return;
if (n <= 0)
return 0;
else if (n == 1)
return 1;
return Fibonacci(n - 2) + Fibonacci(n - 1);
}
var promise = new SimplePromise;
setTimeout(function () {
Fibonacci(100);
promise.resolve();
}, 200);
return promise;
}
// This function ought be as simple as possible. Don't even use SimplePromise.
BenchmarkRunner._runTest = function(suite, testFunction, prepareReturnValue, callback)
{
var self = BenchmarkRunner;
var now = window.performance && window.performance.now ? function () { return window.performance.now(); } : Date.now;
var contentWindow = self._frame.contentWindow;
var contentDocument = self._frame.contentDocument;
var startTime = now();
testFunction(prepareReturnValue, contentWindow, contentDocument);
var endTime = now();
var syncTime = endTime - startTime;
var startTime = now();
setTimeout(function () {
var endTime = now();
callback(syncTime, endTime - startTime);
}, 0);
}
BenchmarkRunner._testName = function (suite, testName, metric) {
if (!testName)
return suite.name;
return suite.name + '/' + testName + (metric ? '/' + metric : '');
}
BenchmarkRunner._testItemId = function (suite, testName) {
return suite.name + '-' + testName;
}
BenchmarkRunner.listSuites = function () {
var self = BenchmarkRunner;
var control = document.createElement('nav');
var suites = self._suites;
var ol = document.createElement('ol');
var checkboxes = [];
for (var suiteIndex = 0; suiteIndex < suites.length; suiteIndex++) {
var suite = suites[suiteIndex];
var li = document.createElement('li');
var checkbox = document.createElement('input');
checkbox.id = suite.name;
checkbox.type = 'checkbox';
checkbox.checked = true;
checkboxes.push(checkbox);
li.appendChild(checkbox);
var label = document.createElement('label');
label.appendChild(document.createTextNode(self._testName(suite)));
li.appendChild(label);
label.htmlFor = checkbox.id;
var testList = document.createElement('ol');
for (var testIndex = 0; testIndex < suite.tests.length; testIndex++) {
var testItem = document.createElement('li');
var test = suite.tests[testIndex];
var anchor = document.createElement('a');
anchor.id = self._testItemId(suite, test[0]);
anchor.appendChild(document.createTextNode(self._testName(suite, test[0])));
testItem.appendChild(anchor);
testList.appendChild(testItem);
}
li.appendChild(testList);
ol.appendChild(li);
}
control.appendChild(ol);
var currentState = null;
// Don't call step while step is already executing.
var button = document.createElement('button');
button.textContent = 'Step';
button.onclick = function () {
self.step(currentState).then(function (state) { currentState = state; });
}
control.appendChild(button);
function callNextStep(state) {
self.step(state).then(function (newState) {
currentState = newState;
if (newState)
callNextStep(newState);
});
}
var button = document.createElement('button');
button.textContent = 'Run';
button.onclick = function () { callNextStep(currentState); }
control.appendChild(button);
document.body.appendChild(control);
}
function BenchmarkState(suites) {
this._suites = suites;
this._suiteIndex = -1;
this._testIndex = 0;
this.next();
}
BenchmarkState.prototype.currentSuite = function() {
return this._suites[this._suiteIndex];
}
BenchmarkState.prototype.currentTest = function () {
var suite = this.currentSuite();
return suite ? suite.tests[this._testIndex] : null;
}
BenchmarkState.prototype.next = function () {
this._testIndex++;
var suite = this._suites[this._suiteIndex];
if (suite && this._testIndex < suite.tests.length)
return this;
this._testIndex = 0;
do {
this._suiteIndex++;
} while (this._suiteIndex < this._suites.length && !document.getElementById(this._suites[this._suiteIndex].name).checked);
return this;
}
BenchmarkState.prototype.isFirstTest = function () {
return !this._testIndex;
}
BenchmarkState.prototype.prepareCurrentSuite = function (frame) {
var self = this;
var suite = this.currentSuite();
var promise = new SimplePromise;
frame.onload = function () {
suite.prepare(frame.contentWindow, frame.contentDocument).then(function (result) { promise.resolve(result); });
}
frame.src = suite.url;
return promise;
}
BenchmarkRunner.step = function (state) {
var self = BenchmarkRunner;
if (!state)
state = new BenchmarkState(self._suites);
var suite = state.currentSuite();
if (!suite) {
self._finalize();
var promise = new SimplePromise;
promise.resolve();
return promise;
}
if (state.isFirstTest()) {
self._masuredValuesForCurrentSuite = {};
return state.prepareCurrentSuite(self._appendFrame()).then(function (prepareReturnValue) {
self._prepareReturnValue = prepareReturnValue;
return self._runTestAndRecordResults(state);
});
}
return self._runTestAndRecordResults(state);
}
BenchmarkRunner._runTestAndRecordResults = function (state) {
var self = BenchmarkRunner;
var promise = new SimplePromise;
var suite = state.currentSuite();
var test = state.currentTest();
var testName = test[0];
var testItem = document.getElementById(self._testItemId(suite, testName));
testItem.classList.add('running');
setTimeout(function () {
self._runTest(suite, test[1], self._prepareReturnValue, function (syncTime, asyncTime) {
self._masuredValuesForCurrentSuite[self._testName(suite, testName, 'Sync')] = syncTime;
self._masuredValuesForCurrentSuite[self._testName(suite, testName, 'Async')] = asyncTime;
testItem.classList.remove('running');
testItem.classList.add('ran');
state.next();
if (state.currentSuite() != suite) {
var total = 0;
for (var title in self._masuredValuesForCurrentSuite) {
var value = self._masuredValuesForCurrentSuite[title];
total += value;
self._measuredValues[title] = value;
}
self._measuredValues[self._testName(suite)] = total;
self._removeFrame();
}
promise.resolve(