Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test123-123-123
(version: 0)
Comparing performance of:
1 vs 2
Created:
4 years ago
by:
Guest
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:
const statuses = { statuses: { closedStatus: { id: 7, name: 'CLOSED', surname: 'Закрыто' }, doneStatus: { id: 81, name: 'COMPLEATE' }, toDevelopersStatus: { id: 7129, name: 'TODEVELOPERS' }, intermediateStatus: { id: 3805, name: 'INTERMEDIATE' }, transferedStatus: { id: 1912, name: "TRANSFERED" }, newStatus: { id: 5, name: 'NEW' }, toNpsStatus: { id: 7347, name: 'TONPS' }, informedStatus: { id: 80, name: 'INFORMED' }, inWorkStatus: { id: 6, name: 'INWORK' } } }; function getStatus(name) { return _.get(_.get(statuses, 'statuses'), name); } function getStatusesBy(prop, ...statuses) { return statuses.reduce((prev, curr) => { return [ ...prev, getStatus(curr)[prop] || getStatus(curr) ] }, []) } function getProhibitedStatuses() { return _.reduce([{ id: 'so' }], (accumulatorProhibitedStatuses, status) => { switch (status.id) { case 'so': return [ ...accumulatorProhibitedStatuses, 'toDevelopersStatus' ]; default: return accumulatorProhibitedStatuses; } }, ['closedStatus']); } function transformToInactiveStatuses(status) { status['inactive'] = true; return status; } function getInactiveSelectionStatuses(statuses) { const arrayIssueStatusId = getStatusesBy(null, ...getProhibitedStatuses()); const inactiveStatuses = _.map(arrayIssueStatusId, (id) => { return transformToInactiveStatuses(id); }); return _.values(_.merge(_.keyBy(statuses, 'id'), _.keyBy(inactiveStatuses, 'id'))); } function getInactiveSelectionStatuses2(statuses) { const arrayIssueStatusId = getStatusesBy(null, ...getProhibitedStatuses()); const inactiveStatuses = _.map(arrayIssueStatusId, (id) => { return transformToInactiveStatuses(id); }); return _.map(statuses, (s => _.find(inactiveStatuses, (iS) => _.isEqual(s.id, iS.id)) || s)); }
Tests:
1
getInactiveSelectionStatuses([{id: 7, name: 'CLOSED'}, {id: 7129, name: 'TODEVELOPERS'}, {id: 5, name: 'NEW'}])
2
getInactiveSelectionStatuses2([{id: 7, name: 'CLOSED'}, {id: 7129, name: 'TODEVELOPERS'}, {id: 5, name: 'NEW'}])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
1
2
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):
**Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The benchmark in question tests the performance of two functions, `getInactiveSelectionStatuses` and `getInactiveSelectionStatuses2`, which are designed to retrieve inactive statuses from an array of status objects. **Script Preparation Code Analysis** The script preparation code defines a set of constants for status names and a namespace for accessing these constants. The code also defines several functions: * `getStatus(name)`: Returns the status object with the given name. * `getStatusesBy(prop, ...statuses)`: Returns an array of values from the statuses objects based on the specified property. * `getProhibitedStatuses()`: Returns an array of prohibited status IDs. * `transformToInactiveStatuses(status)`: Marks a status as inactive by adding an 'inactive' property. * `getInactiveSelectionStatuses(statuses)`: Filters out active statuses and returns the remaining ones. This function uses `getStatusesBy` to get the values from the statuses objects based on the prohibited status IDs. * `getInactiveSelectionStatuses2(statuses)`: Similar to `getInactiveSelectionStatuses`, but it finds the inactive status object with the matching ID in the original array. **Options Compared** The two functions, `getInactiveSelectionStatuses` and `getInactiveSelectionStatuses2`, differ in their approach: * **`getInactiveSelectionStatuses`**: This function uses `getStatusesBy` to get the values from the statuses objects based on the prohibited status IDs. It then filters out active statuses using `transformToInactiveStatuses` and `_.merge`. The resulting inactive statuses are returned as an array. * **`getInactiveSelectionStatuses2`**: This function is similar to `getInactiveSelectionStatuses`, but it uses `_.map` to find the inactive status object with the matching ID in the original array. **Pros and Cons** * **`getInactiveSelectionStatuses`**: * Pros: More efficient, as it only iterates over the prohibited status IDs. * Cons: May not be compatible with all versions of Lodash or require manual updates for compatibility issues. * **`getInactiveSelectionStatuses2`**: * Pros: More flexible and easier to maintain due to its use of `_.map`. * Cons: May have performance overhead due to the iteration over the entire statuses array. **Library Used** The benchmark uses Lodash, a popular JavaScript utility library. The `getStatusesBy`, `getProhibitedStatuses`, and `transformToInactiveStatuses` functions rely on Lodash's `_.get`, `_.reduce`, `_.map`, and other utilities to achieve their functionality. **Special JS Feature or Syntax** The benchmark uses ES6-style arrow functions, which are a concise way of defining small, one-time-use functions. It also employs template literals for string interpolation. **Other Alternatives** If you were to implement these functions from scratch without using Lodash, you could consider the following alternatives: * **Manual iteration**: Implement manual loops over the arrays and objects instead of relying on Lodash's utility functions. * **ES6-style `forEach` loop**: Use a simple `forEach` loop to iterate over the arrays and objects. However, these approaches would likely be less efficient and more error-prone than using established libraries like Lodash.
Related benchmarks:
kjnzjv
reduce/spread4
map and filter vs reduce v2
test spreadpush on2
Combine "set with destructuring" vs "map with push"
Comments
Confirm delete:
Do you really want to delete benchmark?