<script type="text/javascript" src="https://publicstatic.tableausoftware.com/vizql/v_100001608191615/javascripts/mscorlib.js"></script>
<script type="text/javascript" src="https://dl.dropboxusercontent.com/u/2186277/vqlcore.debug.js"></script>
<div id="testRoot">
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
</div>
<div id="testRoot2">
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
</div>
var box = { l: 10, t: 20, w: 30, h: 40 };
tab.DomUtil.setMarginBoxJQ($("#testRoot2"), box);
tab.DomUtil.setMarginBoxJQ2($("#testRoot"), box);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Test 1 | |
Optimized |
Test name | Executions per second |
---|---|
Test 1 | 5628.4 Ops/sec |
Optimized | 13952.2 Ops/sec |
Let's break down the benchmark and its test cases.
Benchmark Overview
The benchmark measures the performance of two different approaches for setting the margin box of an HTML element using the jQuery library (setMarginBoxJQ
and setMarginBoxJQ2
). The goal is to determine which approach is faster, optimized or not.
Script Preparation Code
The script preparation code includes the loading of two external JavaScript files:
https://publicstatic.tableausoftware.com/vizql/v_100001608191615/javascripts/mscorlib.js
: This file likely contains jQuery and its DOM manipulation functions.https://dl.dropboxusercontent.com/u/2186277/vqlcore.debug.js
: This file seems to be a debug version of the VQL (Visualization Query Language) core library.The script also defines a JavaScript object box
with properties l
, t
, w
, and h
.
Html Preparation Code
The HTML preparation code creates two <div>
elements with a span inside each:
<div id="testRoot">
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
</div>
<div id="testRoot2">
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
<span>1</span>
</div>
These HTML elements will be used to test the performance of the two setMarginBoxJQ
approaches.
Individual Test Cases
There are two test cases:
setMarginBoxJQ
function, which is not optimized.setMarginBoxJQ
function, denoted by setMarginBoxJQ2
.Library and Syntax
The benchmark uses jQuery's DOM manipulation functions, specifically $(selector)
to select elements in the HTML document. The setMarginBoxJQ
function takes two arguments: the selected element and an object with the new margin box properties.
There are no special JavaScript features or syntax used in this benchmark.
Options Compared
The two test cases compare the performance of:
setMarginBoxJQ
: This approach is not optimized, meaning it uses a straightforward implementation without any optimizations.setMarginBoxJQ2
: This approach is an optimized version of the original function, likely with improvements such as caching or reduced DOM manipulation.Pros and Cons
Here are some pros and cons of each approach:
setMarginBoxJQ
:setMarginBoxJQ2
:Other Alternatives
If the optimized approach is indeed faster, other alternatives might include:
Keep in mind that the actual results of this benchmark may vary depending on the specific hardware, software, and environment used to run it.