Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set innerText vs textContent
(version: 0)
Comparing performance of:
textContent vs innerText
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = document.createElement('a');
Tests:
textContent
a.textContent = "Text";
innerText
a.innerText = "Text";
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
textContent
innerText
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Browser/OS:
Firefox 115 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
textContent
1842447.1 Ops/sec
innerText
1211875.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided JavaScript microbenchmark. **Benchmark Definition** The benchmark is defined in JSON format, which represents a test case to compare two approaches: setting the `textContent` property versus the `innerText` property on an HTML anchor element (`<a>`) created using `document.createElement('a')`. In summary, this benchmark aims to measure the performance difference between these two ways of assigning text content to an HTML element in modern web browsers. **Options Compared** The options compared are: 1. `textContent`: This property is used to set the text content of an HTML element. It's a more modern and efficient way of setting text content, as it doesn't require parsing or formatting the text. 2. `innerText`: This property is older and was widely supported in web browsers before the introduction of `textContent`. However, it can lead to unexpected behavior if the text contains markup, such as HTML tags. **Pros and Cons** **textContent:** Pros: * More modern and efficient * Doesn't require parsing or formatting the text * Works well with text content that doesn't contain HTML tags Cons: * Not supported in older web browsers (e.g., Internet Explorer) * May not work correctly if used with elements that have complex layouts or styles **innerText:** Pros: * Wider browser support, including older versions of Internet Explorer * Works well with text content that contains HTML tags Cons: * Can lead to unexpected behavior if used with elements that have complex layouts or styles * Requires parsing and formatting the text, which can be slower than `textContent` **Other Considerations** When using these properties, it's essential to consider the context in which they're being used. For example, if you're working with a web application that requires compatibility with older browsers, using `innerText` might be necessary. Additionally, modern web browsers (including Firefox 115) tend to optimize `textContent` for performance, so using this property is generally recommended. **Library or Special JS Feature** There are no libraries or special JavaScript features mentioned in the provided benchmark. The focus is solely on comparing the performance of these two properties. If you're interested in exploring more advanced JavaScript features or libraries that can help with performance optimization, I'd be happy to provide recommendations! **Alternatives** For similar benchmarks, you might want to explore other scenarios, such as: * Comparing the performance of `innerHTML` versus other methods (e.g., `outerHTML`) for setting HTML content. * Measuring the performance of different DOM manipulation approaches (e.g., using `querySelector`, `querySelectorAll`, or `createElement`). * Benchmarking the performance of JavaScript engines or interpreters in different environments. Feel free to ask if you'd like more information on these alternatives!
Related benchmarks:
createTextNode vs textContent vs innerText
innerText vs textContent + trim
textContent vs innerText (read)
createTextNode vs textContent vs innerText vs innerHTML (for reading)
Comments
Confirm delete:
Do you really want to delete benchmark?