<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<table id="tbl">
<tbody></tbody>
</table>
var table = $('#tbl'),
tbody = table.find('tbody');
var data = { one: 'one', two: 'two', three: 'three', four: 'four', five: 'five' };
var tr = $(document.createElement('tr'));
var td = $(document.createElement('td'));
td.text(data.one).append(td);
td = $(document.createElement('td'));
td.text(data.two).append(td);
var td = $(document.createElement('td'));
td.text(data.three).append(td);
var td = $(document.createElement('td'));
td.text(data.four).append(td);
var td = $(document.createElement('td'));
td.text(data.five).append(td);
tbody.append(tr);
var html = '<tr>';
html += '<td>'+data.one+'</td>';
html += '<td>'+data.two+'</td>';
html += '<td>'+data.three+'</td>';
html += '<td>'+data.four+'</td>';
html += '<td>'+data.five+'</td>';
html += '</tr>';
tbody.append(html);
var tr = $(document.createElement('tr'));
tr.append('<td>'+data.one+'</td>');
tr.append('<td>'+data.two+'</td>');
tr.append('<td>'+data.three+'</td>');
tr.append('<td>'+data.four+'</td>');
tr.append('<td>'+data.five+'</td>');
tbody.append(tr);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
createElement | |
Append HTML | |
Combination |
Test name | Executions per second |
---|---|
createElement | 26217.0 Ops/sec |
Append HTML | 22289.4 Ops/sec |
Combination | 6301.9 Ops/sec |
Overview of the Benchmark
The provided JSON represents a JavaScript microbenchmarking test case on the MeasureThat.net website. The test measures the performance of creating and appending table rows in different ways.
What is being tested?
Three individual test cases are compared:
tr
) using document.createElement('tr')
, then appends child elements to it.tbody
element, which contains the table rows.append()
method.Options compared
The three test cases compare different approaches to create and append table rows:
createElement
: Creates a new table row and appends child elements manually.Append HTML
: Appends an entire HTML string to the tbody
element, which includes the table row and its child elements.createElement
and append()
methods to create and append table rows.Pros and Cons of each approach
Library usage
The test case uses jQuery, which is a popular JavaScript library for DOM manipulation. Specifically, it uses $(document.createElement('tr'))
to create a new table row and $(
tbody.append()` to append its child elements.
Special JS feature or syntax
This benchmark does not use any special JavaScript features or syntax that are specific to certain browsers or versions.
Other alternatives
There are other ways to create and append table rows, such as:
innerHTML
instead of createElement
and appendChild
.DOMParser
API to parse an HTML string and create a new element.However, these alternatives may not be relevant to this specific benchmark, which focuses on comparing different approaches to creating and appending table rows using jQuery.