Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test search
(version: 0)
Comparing performance of:
Old func vs New func
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
Old func
const keyword = 'dev'; const words = [ 'Software Development', 'Web Developemnt', 'E-commerce Development', 'Game Developemnt', 'Leadership Development', 'Mobile App Development' ]; words.forEach(text => { const reg = new RegExp(keyword, 'gi'); const matches = text.match(reg); if (!keyword || !matches) { return [{ text, isHighlighted: false }]; } const highlightedFragments = matches.reverse(); const nonHighlightedFragments = text.split(reg); const fragments = []; for (const fragment of nonHighlightedFragments) { fragments.push({ text: fragment, isHighlighted: false }); const highlightedFragment = highlightedFragments.pop(); if (highlightedFragment) { fragments.push({ text: highlightedFragment, isHighlighted: true }); } } });
New func
const keyword = 'dev'; const words = [ 'Software Development', 'Web Developemnt', 'E-commerce Development', 'Game Developemnt', 'Leadership Development', 'Mobile App Development' ]; words.forEach(text => { const reg = new RegExp(`(${keyword})`, 'gi'); if (!keyword || !text) { return [{ text, isHighlighted: false }]; } const search = keyword.toLowerCase(); const fragments = text.split(reg).map(part => { return { text: part, isHighlighted: part.toLowerCase() === search }; }); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Old func
New func
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of MeasureThat.net and explore what's being tested in this benchmark. **Benchmark Overview** The benchmark consists of two test cases, each with its own JavaScript code, which performs a search operation on a list of words. The goal is to measure the performance of these two approaches. **What's Being Tested?** In both test cases, we have: 1. A list of words (`words`) that will be searched. 2. A search keyword (`keyword`) that will be used to find matching words in the list. 3. A regular expression (RegExp) is created using the `keyword`, which is then used to split the text into two parts: highlighted and non-highlighted fragments. The main difference between the two approaches lies in how the RegExp is created and used: **Old Func (Test Case 1)** * The RegExp is created as a literal string, e.g., `const reg = new RegExp(keyword, 'gi');`. * The search keyword is not converted to lowercase before being used with the RegExp. * The regular expression engine will attempt to find a substring in the text that matches the entire keyword. **New Func (Test Case 2)** * The RegExp is created using a template literal, e.g., `const reg = new RegExp(`(${keyword})`, 'gi');`. * The search keyword is converted to lowercase before being used with the RegExp. * The regular expression engine will attempt to find all occurrences of the lowercased keyword in the text. **Pros and Cons** Here's a brief analysis of each approach: **Old Func (Test Case 1)** Pros: * Simple and easy to understand * May perform better for short search keywords Cons: * Can be slower than New Func due to inefficient RegExp creation * May not handle edge cases well, such as partial matches or multi-word searches **New Func (Test Case 2)** Pros: * More efficient RegExp creation using template literals * Handles edge cases better, such as partial matches and multi-word searches Cons: * May be slightly more complex to understand * Requires careful consideration of the search keyword's case sensitivity **Library Used** In both test cases, no specific library is explicitly mentioned. However, it can be assumed that the `RegExp` constructor is used to create the regular expressions. **Special JS Feature or Syntax** No special JavaScript features or syntax are highlighted in this benchmark. The code uses standard JavaScript syntax and features, such as template literals and arrow functions (in the `forEach` callback). **Other Alternatives** If you're interested in exploring other approaches, here are some alternatives: * **Use a dedicated search library**, such as Linq.js or AlgoLib, which provides optimized search functionality. * **Implement your own search algorithm**, using techniques like prefix trees or suffix trees to improve performance. * **Leverage the browser's built-in search capabilities**, using APIs like `navigator.search` or `window.indexedDB.open()`.
Related benchmarks:
[test] for vs find
filter vs some vs includes vs find
findIndex vs for loop test
Object arrays: find vs for loop
.includes() vs .test() vs .match() vs .indexOf() vs .search() fix2
Comments
Confirm delete:
Do you really want to delete benchmark?