<html>
<head>
<title>Operation VS Character</title>
</head>
<body>
<div id='el-target'>
TEST
</div>
</body>
</html>
(()=>{
document.getElementById("el-target").innerHTML = "TEST";
document.getElementById("el-target").innerHTML = "TEST";
document.getElementById("el-target").innerHTML = "TEST";
document.getElementById("el-target").innerHTML = "TEST";
document.getElementById("el-target").innerHTML = "TEST";
document.getElementById("el-target").innerHTML = "TEST";
document.getElementById("el-target").innerHTML = "TEST";
document.getElementById("el-target").innerHTML = "TEST";
document.getElementById("el-target").innerHTML = "TEST";
document.getElementById("el-target").innerHTML = "TEST";
})();
(()=>{
const getByiD = (id)=>{
return document.getElementById(id);
};
const setInner = (el, content)=>{
el.innerHTML = content;
};
setInner(getByiD("el-target"), "TEST");
setInner(getByiD("el-target"), "TEST");
setInner(getByiD("el-target"), "TEST");
setInner(getByiD("el-target"), "TEST");
setInner(getByiD("el-target"), "TEST");
setInner(getByiD("el-target"), "TEST");
setInner(getByiD("el-target"), "TEST");
setInner(getByiD("el-target"), "TEST");
setInner(getByiD("el-target"), "TEST");
setInner(getByiD("el-target"), "TEST");
})();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
vs | |
vc |
Test name | Executions per second |
---|---|
vs | 23670.7 Ops/sec |
vc | 23805.8 Ops/sec |
Let's break down the provided benchmark definition and test cases to understand what's being tested.
Benchmark Definition
The benchmark is defined by a JSON object that provides metadata about the test, such as its name and description. The script preparation code and HTML preparation code are also specified, which will be used to set up the testing environment.
In this case, the script preparation code is null
, which means no additional setup code needs to be executed before running the benchmark. The HTML preparation code creates a basic HTML page with a <div>
element named "el-target" that will serve as the target for the test.
Individual Test Cases
There are two test cases defined:
This test case consists of a single line of JavaScript code that sets the innerHTML property of the "el-target" element multiple times using a simple assignment (document.getElementById("el-target").innerHTML = "TEST"
). This is likely intended to measure the performance of setting the innerHTML property.
This test case also consists of a single line of JavaScript code that sets the innerHTML property of the "el-target" element multiple times using an intermediate function (setInner
and getByiD
). The getByiD
function takes an ID as an argument and returns the corresponding DOM element, which is then passed to the setInner
function along with the string content. This test case introduces an additional layer of indirection by creating a separate function for setting the innerHTML property.
Library Used
In both test cases, no external libraries are used beyond the standard JavaScript DOM API. However, the use of getByiD
and setInner
functions in the "vc" test case suggests that these might be custom utility functions created to improve performance or readability.
Special JS Features/Syntax
Neither of the test cases uses any special JavaScript features or syntax beyond what's standard for modern JavaScript. There are no ES6+ features, asynchronous code, or other advanced concepts present in the benchmark definition.
Options Compared
In this case, two options are compared:
document.getElementById("el-target").innerHTML = "TEST"
)This approach uses a simple assignment to set the innerHTML property of the element multiple times.
setInner
and getByiD
)This approach introduces an additional layer of indirection by creating separate functions for getting the DOM element and setting its innerHTML property. The intermediate function might be intended to reduce overhead or improve performance.
Pros and Cons
Simple Assignment:
Pros:
Cons:
Intermediate Function:
Pros:
Cons:
getByiD
and setInner
functionsOther Considerations
In addition to the options compared, there are other factors that might influence the performance of this benchmark. These include:
Alternatives
If you were to recreate these benchmarks using a different approach, here are some alternatives to consider:
I hope this explanation helps you understand what's being tested in MeasureThat.net!