Skip to content

Commit

Permalink
[performance] use individual files rather than the build, revamp the …
Browse files Browse the repository at this point in the history
…attrs code to reduce variance, reset the scratch pad more reliably
  • Loading branch information
pygy committed Jun 7, 2018
1 parent 8daa386 commit 15cf47a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
4 changes: 3 additions & 1 deletion performance/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<script src="../test-utils/pushStateMock.js"></script>
<script src="../test-utils/xhrMock.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/benchmark/benchmark.js"></script>
<script src="test-perf.js"></script>
Expand Down
47 changes: 28 additions & 19 deletions performance/test-perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var browserMock = require("../test-utils/browserMock")
// Do this silly dance so browser testing works
var B = typeof Benchmark === "undefined" ? require("benchmark") : Benchmark

var m, scratch;
var scratch;

// set up browser env on before running tests
var doc = typeof document !== "undefined" ? document : null
Expand All @@ -43,12 +43,16 @@ if(!doc) {
doc = mock.document
}

// Have to include mithril AFTER browser polyfill is set up
m = require("../mithril") // eslint-disable-line global-require
var m = require("../render/hyperscript")
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
var suite = new B.Suite("mithril perf")
Expand All @@ -61,7 +65,7 @@ suite.on("start", function() {
suite.on("cycle", function(e) {
console.log(e.target.toString())

scratch.innerHTML = ""
resetScratch()
})

suite.on("complete", function() {
Expand Down Expand Up @@ -260,21 +264,26 @@ suite.add({

this.count = 0
this.app = function (index) {
return m("div.booga",
{
class: get(classes, index),
"data-index": index,
title: index.toString(36)
},
m("input.dooga", {type: "checkbox", checked: index % 3 == 0}),
m("input", {value: "test " + (Math.floor(index / 4)), disabled: index % 10 ? null : true}),
m("div", {class: get(classes, index * 11)},
m("p", {style: get(styles, index)}, "p1"),
m("p", {style: get(styles, index + 1)}, "p2"),
m("p", {style: get(styles, index * 2)}, "p3"),
m("p.zooga", {style: get(styles, index * 3 + 1), className: get(classes, index * 7)}, "p4")
var last = index + 300
var vnodes = []
for (; index < last; index++) vnodes.push(
m("div.booga",
{
class: get(classes, index),
"data-index": index,
title: index.toString(36)
},
m("input.dooga", {type: "checkbox", checked: index % 3 == 0}),
m("input", {value: "test " + (Math.floor(index / 4)), disabled: index % 10 ? null : true}),
m("div", {class: get(classes, index * 11)},
m("p", {style: get(styles, index)}, "p1"),
m("p", {style: get(styles, index + 1)}, "p2"),
m("p", {style: get(styles, index * 2)}, "p3"),
m("p.zooga", {style: get(styles, index * 3 + 1), className: get(classes, index * 7)}, "p4")
)
)
)
return vnodes
}
},

Expand Down

0 comments on commit 15cf47a

Please sign in to comment.