Dom操作-元素添加

Benchmark created on


Preparation HTML

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
</body>
</html>

Test runner

Ready to run.

Testing in
TestOps/sec
innerHTML
document.body.innerHTML = '<div>Hello JavaScript</div>'
const div = document.createElement("div")
div.innerHTML = "<p>Hello, world!</p>";  
document.body.appendChild(div);


ready
appendChild
document.body.innerHTML = '<div>Hello JavaScript</div>'
const div = document.createElement("div")
const p = document.createElement("p");
p.textContent = "Hello, world!";
div.appendChild(p);
document.body.appendChild(div);


ready
insertBefore
document.body.innerHTML = '<div>Hello JavaScript</div>'
const div = document.createElement("div");  
const p = document.createElement("p");  
p.textContent = "Hello, world!";  
div.appendChild(p);  
document.body.insertBefore(div, document.body.firstChild);


ready

Revisions

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