var toDom = function(){var a=document.createElement("div");a.innerHTML=this;return a.firstChild}
var mkDom = function(s){var a=document.createElement("div");a.innerHTML=s;return a.firstChild}
var testString = "<div id='test'></div>";
var d = toDom.apply(testString);
var d = mkDom(testString);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
toDom | |
mkDom |
Test name | Executions per second |
---|---|
toDom | 109536.2 Ops/sec |
mkDom | 147365.5 Ops/sec |
Let's break down the benchmark and explain what is being tested.
Benchmark Overview
The benchmark compares two JavaScript functions: toDom
and mkDom
. These functions are designed to create an HTML element with a specific string as its inner HTML content. The difference between the two functions lies in how they handle this task.
Options Compared
The two functions, toDom
and mkDom
, differ in their approach to creating the HTML element:
toDom
function:document.createElement("div")
to create a new <div>
element.innerHTML
property with the input string (this
or an argument).mkDom
function:document.createElement("div")
to create a new <div>
element.s
).Pros and Cons
Here are some pros and cons of each approach:
toDom
function:this
refers to a valid value.mkDom
function:Library Usage
There is no explicit library used in this benchmark. However, it's worth noting that innerHTML
and createElement
are part of the DOM API, which is a built-in JavaScript API for manipulating HTML documents.
Special JS Features/Syntax
This benchmark does not use any special JavaScript features or syntax. The code is standard JavaScript and can be run in most modern browsers or environments.
Other Alternatives
If you were to rewrite this benchmark, you could consider alternative approaches:
In summary, this benchmark provides a straightforward comparison between two JavaScript functions that create HTML elements from input strings. While it doesn't use any special features or libraries, alternative approaches can be explored depending on the specific requirements and constraints of the project.