2018-02-27 07:23:59 +01:00
|
|
|
/* global Snap */
|
2016-08-04 18:06:22 +02:00
|
|
|
|
2018-02-27 07:23:59 +01:00
|
|
|
;(function () {
|
2016-08-04 18:06:22 +02:00
|
|
|
SVG.bench = {
|
|
|
|
// Initalize test store
|
2018-02-27 07:23:59 +01:00
|
|
|
_chain: [],
|
|
|
|
_before: function () {},
|
|
|
|
_after: function () {},
|
|
|
|
draw: SVG().addTo('#draw'),
|
|
|
|
snap: Snap(100, 100),
|
|
|
|
raw: document.getElementById('native'),
|
2016-08-04 18:06:22 +02:00
|
|
|
|
2016-08-06 09:31:44 +02:00
|
|
|
// Add descriptor
|
2018-02-27 07:23:59 +01:00
|
|
|
describe: function (name, closure) {
|
2016-08-06 09:31:44 +02:00
|
|
|
this._chain.push({
|
2018-02-27 07:23:59 +01:00
|
|
|
name: name,
|
|
|
|
run: closure
|
2016-08-04 18:06:22 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
return this
|
2018-02-27 07:23:59 +01:00
|
|
|
},
|
2016-08-04 18:06:22 +02:00
|
|
|
|
2016-08-06 09:31:44 +02:00
|
|
|
// Add test
|
2018-02-27 07:23:59 +01:00
|
|
|
test: function (name, run) {
|
2016-08-06 09:31:44 +02:00
|
|
|
// run test
|
2018-02-27 07:23:59 +01:00
|
|
|
var start = (new Date()).getTime()
|
2016-08-06 09:31:44 +02:00
|
|
|
run()
|
2018-02-27 07:23:59 +01:00
|
|
|
this.write(name, (new Date()).getTime() - start)
|
2016-08-06 09:31:44 +02:00
|
|
|
|
|
|
|
// clear everything
|
|
|
|
this.clear()
|
2018-02-27 07:23:59 +01:00
|
|
|
},
|
2016-08-04 18:06:22 +02:00
|
|
|
|
2016-08-06 09:31:44 +02:00
|
|
|
// Skip test
|
2018-02-27 07:23:59 +01:00
|
|
|
skip: function (name, run) {
|
|
|
|
this.write(name, false)
|
|
|
|
},
|
2016-08-04 18:06:22 +02:00
|
|
|
|
|
|
|
// Run tests
|
2018-02-27 07:23:59 +01:00
|
|
|
run: function () {
|
2017-02-21 09:43:13 +01:00
|
|
|
this.pad()
|
2018-02-27 07:23:59 +01:00
|
|
|
|
2016-08-06 09:31:44 +02:00
|
|
|
for (var h, i = 0, il = this._chain.length; i < il; i++) {
|
2018-02-27 07:23:59 +01:00
|
|
|
h = document.createElement('h1')
|
2016-08-06 09:31:44 +02:00
|
|
|
h.innerHTML = this._chain[i].name
|
|
|
|
this.pad().appendChild(h)
|
|
|
|
this._chain[i].run(this)
|
2016-08-04 18:06:22 +02:00
|
|
|
}
|
2018-02-27 07:23:59 +01:00
|
|
|
},
|
|
|
|
|
2016-08-04 18:06:22 +02:00
|
|
|
// Write result
|
2018-02-27 07:23:59 +01:00
|
|
|
write: function (name, ms) {
|
2016-08-04 18:06:22 +02:00
|
|
|
var test = document.createElement('div')
|
|
|
|
|
2016-08-06 09:31:44 +02:00
|
|
|
if (typeof ms === 'number') {
|
|
|
|
test.className = 'test'
|
|
|
|
test.innerHTML = '<span class="name">' + name + '</span> completed in <span class="ms">' + ms + 'ms</span>'
|
|
|
|
} else {
|
|
|
|
test.className = 'test skipped'
|
|
|
|
test.innerHTML = name + ' (skipped)'
|
|
|
|
}
|
2018-02-27 07:23:59 +01:00
|
|
|
|
2016-08-04 18:06:22 +02:00
|
|
|
this.pad().appendChild(test)
|
|
|
|
|
|
|
|
return this
|
2018-02-27 07:23:59 +01:00
|
|
|
},
|
2016-08-04 18:06:22 +02:00
|
|
|
|
|
|
|
// Reference writable element
|
2018-02-27 07:23:59 +01:00
|
|
|
pad: function () {
|
2016-08-04 18:06:22 +02:00
|
|
|
var pad = document.getElementById('pad')
|
|
|
|
|
2016-08-06 09:31:44 +02:00
|
|
|
if (!pad) {
|
2016-08-04 18:06:22 +02:00
|
|
|
pad = document.createElement('div')
|
|
|
|
document.getElementsByTagName('body')[0].appendChild(pad)
|
|
|
|
}
|
|
|
|
|
|
|
|
return pad
|
2018-02-27 07:23:59 +01:00
|
|
|
},
|
2016-08-04 18:33:26 +02:00
|
|
|
|
|
|
|
// Clear canvasses
|
2018-02-27 07:23:59 +01:00
|
|
|
clear: function () {
|
|
|
|
while (this.raw.hasChildNodes()) {
|
2016-08-04 18:33:26 +02:00
|
|
|
this.raw.removeChild(this.raw.lastChild)
|
2018-02-27 07:23:59 +01:00
|
|
|
}
|
2016-08-04 18:33:26 +02:00
|
|
|
this.draw.clear()
|
2016-08-04 21:19:53 +02:00
|
|
|
this.snap.clear()
|
2016-08-04 18:33:26 +02:00
|
|
|
}
|
2016-08-04 18:06:22 +02:00
|
|
|
}
|
2018-02-27 07:23:59 +01:00
|
|
|
})()
|