Templating in Knockout.js
JavaScript performance comparison
Preparation code
<script src="https://github.com/SteveSanderson/knockout/raw/master/build/output/knockout-latest.debug.js">
</script>
<script src="https://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.js">
</script>
<ul data-bind="template: { name: 'itemTmpl', foreach: items }">
</ul>
<script id="itemTmpl" type="text/html">
<li data-bind = "text: name"> </li>
</script>
<script>
function Item(id, name, type) {
return {
id: ko.observable(id),
name: ko.observable(name),
type: ko.observable(type)
}
}
var viewModel = {
name: ko.observable("nameTest"),
person: ko.observable({
firstName: "Bob"
}),
items: ko.observableArray([
new Item(1, "one", "a"), new Item(2, "two", "b"), new Item(3, "three", "a")]),
itemFlag: ko.observable(true)
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
KO native templating |
|
pending… |
jquery templating |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Scott Messinger
- Revision 2: published
- Revision 3: published by Scott Messinger
- Revision 5: published by Scott Messinger
- Revision 6: published by Scott Messinger
- Revision 7: published by Ryan Niemeyer
- Revision 8: published by Michael Best
- Revision 9: published by Michael Best
- Revision 12: published
- Revision 13: published
- Revision 14: published
- Revision 16: published
- Revision 17: published
- Revision 18: published
- Revision 19: published
- Revision 20: published
- Revision 21: published
- Revision 22: published
- Revision 23: published by thelinuxlich
- Revision 24: published
- Revision 25: published by Andrew Jameson
- Revision 26: published
0 comments