Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Character position - Triet
(version: 0)
Comparing performance of:
Vanilla vs Vanilla map vs Lodash map vs Lodash reduce vs Lodash chain map
Created:
8 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var source = "scissors"; var result = null;
Tests:
Vanilla
result = []; for(var i=0; i<source.length;i++) { if (source[i] === "s") result.push(i); }
Vanilla map
result = source.split('').map((c, i) => { return c === 's' ? i : null; }).filter(x => x !== null);
Lodash map
result = _.filter(_.map(source, (c, i) => { return c === 's' ? i : null; }), (x) => x !== null);
Lodash reduce
result = _.reduce(source, (result, value, key) => { value === 's' && result.push(key); return result; }, []);
Lodash chain map
result = _(source).map((c, i) => { return c === 's' ? i : null; }).filter(x => x !== null).value();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Vanilla
Vanilla map
Lodash map
Lodash reduce
Lodash chain map
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 break down what's being tested in this benchmark. **Overview** The benchmark is designed to measure the performance of different approaches for finding the indices of a specific character in a string. The input string "scissors" contains two 's' characters, and we want to find their positions. **Approaches compared** There are four approaches compared: 1. **Vanilla**: Uses a simple `for` loop with indexing to find the indices. 2. **Vanilla map**: Uses the `Array.prototype.map()` method to create a new array with the indices as values. 3. **Lodash map**: Uses the `_filter()` and `_map()` functions from the Lodash library to achieve the same result. 4. **Lodash reduce**: Uses the `_reduce()` function from the Lodash library to find the indices. **Pros and Cons** 1. **Vanilla**: Pros - Simple, efficient for small inputs. Cons - May be slower for large inputs due to indexing overhead. 2. **Vanilla map**: Pros - Easy to read, expressive code. Cons - May not be optimized for performance, creates a new array with indices. 3. **Lodash map**: Pros - Utilizes Lodash's optimization and caching, easy to understand. Cons - Adds an external library dependency, may not be suitable for very small inputs. 4. **Lodash reduce**: Pros - Uses Lodash's accumulator-based approach, efficient for large inputs. Cons - May have a steeper learning curve due to the accumulator pattern. **Library usage** In this benchmark, the Lodash library is used in two ways: * `_filter()` and `_map()` functions are used together to find the indices. * `_reduce()` function is used alone to find the indices. **Special JavaScript features or syntax** None mentioned in this specific benchmark. However, it's worth noting that some of these approaches may use modern JavaScript features like `const`, `let`, or ES6 arrow functions (`=>`), but they are not explicitly mentioned here. **Other alternatives** If we consider alternative approaches, we might look at: * Using a different library or framework for string manipulation (e.g., Regular Expressions). * Implementing the solution in a different language (e.g., C++). However, the current benchmark focuses on JavaScript-specific solutions using popular libraries and techniques. **Benchmark setup** The benchmark is set up to run each approach multiple times (likely 1000-10000) and measure the execution time per second. The results are reported as `ExecutionsPerSecond`, which gives an idea of how many iterations can be completed in a single second.
Related benchmarks:
AB toggles check
Lodash vs vanila 2
Lodash vs vanila 3.2
Lodash vs vanila 3.3
Lodash some vs JS some 1
Comments
Confirm delete:
Do you really want to delete benchmark?