Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
sanitize-html vs lodash
(version: 0)
Comparing performance of:
lodash vs sanitize-html
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/sanitize-html/1.27.5/sanitize-html.min.js" integrity="sha512-1WdDeZGPykoWawFKD3NGJfZM+4hq2+OxUF8ZJrrqFBNU3J+Q5Tgvn+XwHNt8HaVs1MRFFlAgtOgyJr6/mqN/xw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Script Preparation code:
const escape = title => _.escape(_.unescape(title))
Tests:
lodash
console.log(escape("&ds;<")) console.log(escape("<속보>")) console.log(escape("<속보>")) console.log(escape("<marquee></marquee>")) console.log(escape("<marquee>속보</marquee>")) console.log(escape("<marquee><속보></marquee>")) console.log(escape("<b><속보></b>")) console.log(escape("<b><속보></b>"))
sanitize-html
console.log(sanitizeHtml("&ds;<")) console.log(sanitizeHtml("<속보>")) console.log(sanitizeHtml("<속보>")) console.log(sanitizeHtml("<marquee></marquee>")) console.log(sanitizeHtml("<marquee>속보</marquee>")) console.log(sanitizeHtml("<marquee><속보></marquee>")) console.log(sanitizeHtml("<b><속보></b>")) console.log(sanitizeHtml("<b><속보></b>"))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
sanitize-html
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0
Browser/OS:
Chrome 142 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash
25047.6 Ops/sec
sanitize-html
9461.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and explain what's being tested. **Benchmark Definition** The benchmark is comparing two JavaScript functions: `escape` from the Lodash library and `sanitizeHtml` from the Sanitize HTML library. **What's being compared?** The test cases are designed to measure the performance of each function when escaping a specific set of HTML characters. The goal is to determine which function can process these characters more efficiently. **Options compared:** 1. **Lodash escape function**: The `escape` function from Lodash is used to sanitize and escape HTML characters. 2. **Sanitize HTML library**: The `sanitizeHtml` function from the Sanitize HTML library is used to sanitize and escape HTML characters. **Pros and Cons of each approach:** **Lodash Escape Function:** Pros: * Well-established and widely used library * Provides a robust set of features for HTML escaping Cons: * May have additional overhead due to its feature-rich nature * Can be slower than a dedicated HTML sanitizer **Sanitize HTML Library:** Pros: * Optimized specifically for HTML sanitization, reducing overhead * Designed to handle complex edge cases and HTML entities Cons: * Less widely used compared to Lodash * May have fewer features and options **Special considerations:** 1. The test uses `_.escape` and `_unescape` functions from Lodash, which can lead to additional overhead due to the need for escape and unescape operations. 2. The Sanitize HTML library uses a more efficient approach by directly sanitizing and escaping the input HTML. **Other alternatives:** If not using Lodash or the Sanitize HTML library, developers could consider other HTML sanitization libraries like DOMPurify or jshtml. These libraries are designed specifically for HTML sanitization and may offer better performance than a generic escape function from a library like Lodash. Keep in mind that the choice of library ultimately depends on the specific use case and requirements of your project.
Related benchmarks:
Dompurify 2.3.3 vs sanitize-html 1.27.5 vs Js-XSS Latest (Test #1)
sanitize-html with escaping option vs lodash
Lodash.get vs native [Krosnoz]
mergeWith lodash vs immutable
Comments
Confirm delete:
Do you really want to delete benchmark?