Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Underscore pluck vs map 5
(version: 0)
Comparing performance of:
Underscore vs Native
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.0/underscore.js"></script>
Script Preparation code:
var data = [ {id: 1, status:'ok'}, {id: 2, status:'ok'}, {id: 3, status:'ok'}, {id: 4, status:'ok'}, {id: 5, status:'ok'}, {id: 6, status:'ok'}, {id: 7, status:'ok'}, {id: 8, status:'ok'}, {id: 9, status:'ok'}, {id: 10, status:'ok'}, {id: 1, status:'ok'}, {id: 2, status:'ok'}, {id: 3, status:'ok'}, {id: 4, status:'ok'}, {id: 5, status:'ok'}, {id: 6, status:'ok'}, {id: 7, status:'ok'}, {id: 8, status:'ok'}, {id: 9, status:'ok'}, {id: 10, status:'ok'}, {id: 1, status:'ok'}, {id: 2, status:'ok'}, {id: 3, status:'ok'}, {id: 4, status:'ok'}, {id: 5, status:'ok'}, {id: 6, status:'ok'}, {id: 7, status:'ok'}, {id: 8, status:'ok'}, {id: 9, status:'ok'}, {id: 10, status:'ok'}, {id: 1, status:'ok'}, {id: 2, status:'ok'}, {id: 3, status:'ok'}, {id: 4, status:'ok'}, {id: 5, status:'ok'}, {id: 6, status:'ok'}, {id: 7, status:'ok'}, {id: 8, status:'ok'}, {id: 9, status:'ok'}, {id: 10, status:'ok'}, {id: 1, status:'ok'}, {id: 2, status:'ok'}, {id: 3, status:'ok'}, {id: 4, status:'ok'}, {id: 5, status:'ok'}, {id: 6, status:'ok'}, {id: 7, status:'ok'}, {id: 8, status:'ok'}, {id: 9, status:'ok'}, {id: 10, status:'ok'}, ];
Tests:
Underscore
var result = _.pluck(data, "id");
Native
var result = data.map(item => item.id);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Underscore
Native
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 Explanation** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided JSON represents a benchmark test case called "Underscore pluck vs map 5". This test compares the performance of two approaches: using the Underscore.js library's `pluck` method versus the native `map` function in JavaScript. **Options Compared** The benchmark tests two options: 1. **Underscore.js's `pluck` method**: This option uses the `pluck` function from the Underscore.js library to extract a subset of values from an array. In this case, it is used to extract the `id` property from each object in the `data` array. 2. **Native JavaScript's `map` function**: This option uses the built-in `map` function to create a new array with the results of applying a provided function to each element in the original array. In this case, it is used to extract the `id` property from each object in the `data` array. **Pros and Cons** Here are some pros and cons of each approach: **Underscore.js's `pluck` method** Pros: * Can be more efficient than using native `map` for small arrays. * Reduces boilerplate code. Cons: * Adds an external dependency (the Underscore.js library). * May have additional overhead due to the library's implementation. **Native JavaScript's `map` function** Pros: * Does not add any external dependencies. * Can be more flexible and customizable. Cons: * Requires more boilerplate code to extract a subset of values from an array. * May be slower for large arrays. **Other Considerations** Both approaches have their trade-offs. The Underscore.js library provides a simple and efficient way to perform common data manipulation tasks, but it requires adding an external dependency. On the other hand, using native JavaScript's `map` function gives more control over the implementation, but may require more code. **Library Used - Underscore.js** Underscore.js is a popular JavaScript library that provides a set of functional programming helpers, including the `pluck` method used in this benchmark. The `pluck` method takes two arguments: an array and a property name (in this case, `"id"`). It returns a new array with the values from the original array that correspond to the specified property. **Special JS Feature/ Syntax** There is no special JavaScript feature or syntax used in this benchmark. Both options use standard JavaScript functions and methods.
Related benchmarks:
Loop perf
Underscore pluck vs map 2
Underscore pluck vs map 4
filter + map vs flatMap
Comments
Confirm delete:
Do you really want to delete benchmark?