Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Filtering Large Lists
(version: 14)
Comparing performance of:
Regex case vs Indexof no trime, begins with vs Indexof trim, begins with
Created:
8 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var list = [...Array(1000000).keys()].map((index) => `ITEM_${index}`); var val = 'ITEM_100';
Tests:
Regex case
const trimVal = val.trim(); const regex = new RegExp(`^${trimVal}`, 'i'); const x = list.filter((item) => { return trimVal !== '' ? regex.test(item) : true; });
Indexof no trime, begins with
const lowerVal = val.toLowerCase(); const x = list.filter((item) => { return val !== '' ? item.toLowerCase().indexOf(lowerVal) === 0: true; });
Indexof trim, begins with
const trimVal = val.trim().toLowerCase(); const x = list.filter((item) => { return trimVal !== '' ? item.toLowerCase().indexOf(trimVal) === 0 : true; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Regex case
Indexof no trime, begins with
Indexof trim, begins with
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Regex case
54.2 Ops/sec
Indexof no trime, begins with
33.0 Ops/sec
Indexof trim, begins with
32.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Overview** The benchmark is designed to measure the performance of filtering large lists using different string manipulation techniques. The benchmark uses JavaScript as the programming language. **Script Preparation Code** The script preparation code creates a list of 1,000,000 elements with unique names (ITEM_0, ITEM_1, ..., ITEM_999,999) and assigns it to the `list` variable. It also defines a string value (`val`) that will be used in the benchmark. **Html Preparation Code** There is no HTML preparation code provided, which means the benchmark only runs in a JavaScript environment (e.g., web browser). **Test Cases** There are three test cases: 1. **Regex Case**: This test case uses regular expressions to filter the list. The script defines a regular expression (`regex`) that matches strings starting with `val` (the trimmed value of `trimVal`). It then filters the list using this regex. 2. **Indexof No Trim, Begins With**: In this test case, the script converts `val` to lowercase and uses the `indexOf` method to find the index of the first occurrence of `lowerVal` in each string (i.e., a string that starts with `val`). It then filters the list using this condition. 3. **Indexof Trim, Begins With**: Similar to the previous test case, but it trims `val` before converting it to lowercase and using `indexOf`. **Library Usage** None of these test cases use any external libraries. **Special JS Features or Syntax** These test cases demonstrate some common JavaScript string manipulation techniques: * Regular expressions (`regex`) * String trimming (`trimVal = val.trim()` and similar) * Case conversion (`lowerVal`) **Other Considerations** When interpreting the benchmark results, consider the following factors: * **Cache performance**: Since the list of 1,000,000 elements is created in advance, cache effects may play a role in how quickly each test case executes. Browsers with fast caches might execute these tests more quickly than those without. * **String pool optimization**: JavaScript engines have mechanisms to optimize string literals by reusing them in the same scope. These optimizations can affect performance. **Alternative Benchmarking Scenarios** Other benchmarking scenarios that could be used to compare these test cases include: * Filtering a smaller list (e.g., 10,000 elements) * Using different data structures (e.g., arrays of objects instead of strings) * Implementing filtering using custom loop constructs instead of built-in methods like `filter`
Related benchmarks:
array last element big data
Lodash some v. Array.some
Map convert
includes indexOf
popopop
Comments
Confirm delete:
Do you really want to delete benchmark?