[performance] use individual files rather than the build, revamp the attrs code to reduce variance, reset the scratch pad more reliably

This commit is contained in:
Pierre-Yves Gérardy 2018-06-07 00:24:14 +02:00 committed by Pierre-Yves Gérardy
parent 8daa386e5e
commit 15cf47a829
2 changed files with 31 additions and 20 deletions

View file

@ -13,7 +13,9 @@
<script src="../test-utils/pushStateMock.js"></script> <script src="../test-utils/pushStateMock.js"></script>
<script src="../test-utils/xhrMock.js"></script> <script src="../test-utils/xhrMock.js"></script>
<script src="../test-utils/browserMock.js"></script> <script src="../test-utils/browserMock.js"></script>
<script src="../mithril.js"></script> <script src="../render/vnode.js"></script>
<script src="../render/render.js"></script>
<script src="../render/hyperscript.js"></script>
<script src="../node_modules/lodash/lodash.js"></script> <script src="../node_modules/lodash/lodash.js"></script>
<script src="../node_modules/benchmark/benchmark.js"></script> <script src="../node_modules/benchmark/benchmark.js"></script>
<script src="test-perf.js"></script> <script src="test-perf.js"></script>

View file

@ -31,7 +31,7 @@ var browserMock = require("../test-utils/browserMock")
// Do this silly dance so browser testing works // Do this silly dance so browser testing works
var B = typeof Benchmark === "undefined" ? require("benchmark") : Benchmark var B = typeof Benchmark === "undefined" ? require("benchmark") : Benchmark
var m, scratch; var scratch;
// set up browser env on before running tests // set up browser env on before running tests
var doc = typeof document !== "undefined" ? document : null var doc = typeof document !== "undefined" ? document : null
@ -43,12 +43,16 @@ if(!doc) {
doc = mock.document doc = mock.document
} }
// Have to include mithril AFTER browser polyfill is set up var m = require("../render/hyperscript")
m = require("../mithril") // eslint-disable-line global-require m.render = require("../render/render")(window).render
scratch = doc.createElement("div");
(doc.body || doc.documentElement).appendChild(scratch) function resetScratch() {
doc.documentElement.innerHTML = "<div></div>"
scratch = doc.documentElement.firstChild
}
resetScratch()
// Initialize benchmark suite // Initialize benchmark suite
var suite = new B.Suite("mithril perf") var suite = new B.Suite("mithril perf")
@ -61,7 +65,7 @@ suite.on("start", function() {
suite.on("cycle", function(e) { suite.on("cycle", function(e) {
console.log(e.target.toString()) console.log(e.target.toString())
scratch.innerHTML = "" resetScratch()
}) })
suite.on("complete", function() { suite.on("complete", function() {
@ -260,7 +264,10 @@ suite.add({
this.count = 0 this.count = 0
this.app = function (index) { this.app = function (index) {
return m("div.booga", var last = index + 300
var vnodes = []
for (; index < last; index++) vnodes.push(
m("div.booga",
{ {
class: get(classes, index), class: get(classes, index),
"data-index": index, "data-index": index,
@ -275,6 +282,8 @@ suite.add({
m("p.zooga", {style: get(styles, index * 3 + 1), className: get(classes, index * 7)}, "p4") m("p.zooga", {style: get(styles, index * 3 + 1), className: get(classes, index * 7)}, "p4")
) )
) )
)
return vnodes
} }
}, },