jQuery Template compiled vs not compiled (v2)

Revision 2 of this benchmark created by blackjid on


Description

This is a test for jQuery templating to see if update is anywhere faster than re-rendering.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script>

<script type="x-jquery-tmpl" id="tmplRow">
<tr>
    <td>
    {{if $data.DisplayFullName}}
        ${FullName}
    {{else}}
        ${FirstName} ${LastName}
    {{/if}}
    </td>
</tr>
</script>

<script type="x-jquery-tmpl" id="tmplTbody">
<tbody>
{{each Rows}}
    {{tmpl($value) '#tmplRow'}}
{{/each}}
</tbody>
</script>

<table id="table"></table>

<script>


</script>

Setup

data = {
            Rows: []
        };
    
        for (var i = 0; i < 100; i++) {
    
            var row = {
                FirstName: 'john',
                LastName: 'doe',
                FullName: 'This is a full name',
                DisplayFullName: i % 2 == 0
            }
    
            data.Rows.push(row);
        }

Test runner

Ready to run.

Testing in
TestOps/sec
Compiled
var com = $('#tmplTbody').template();
$.tmpl(com, data).appendTo('#table');
ready
Not compiled
$('#tmplTbody').tmpl(data).appendTo('#table');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Chi Chan on
  • Revision 2: published by blackjid on