Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
FieldeasReduce6-3
(version: 2)
Comparing performance of:
tail vs jimmy reduce vs tail 2
Created:
5 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src=''></script>
Script Preparation code:
var testData = { keys: ["ID", "ID_CONTACT", "ID_CHAT", "DATE", "TEXT", "BLOB", "$HDN_BIN_BLOB", "HAS_BLOB", "BLOB_TYPE", "BLOB_DURATION", "BLOB_SIZE", "$HDN_DateTime", "$HDN_XCoord", "$HDN_YCoord", "$HDN_ZCoord", "$PK", "$HDN_IDState", "$HDN_DescState", "$HDN_NumBlob"], values: [] }; for (var i = 0; i < 1000; i++) { testData.values.push([ "ID", "ID_CONTACT" + i, "ID_CHAT" + i, "DATE" + i, "TEXT" + i, "BLOB" + i, "$HDN_BIN_BLOB" + i, "HAS_BLOB" + i, "BLOB_TYPE" + i, "BLOB_DURATION" + i, "BLOB_SIZE" + i, "$HDN_DateTime" + i, "$HDN_XCoord" + i, "$HDN_YCoord" + i, "$HDN_ZCoord" + i, "$PK" + i, "$HDN_IDState" + i, "$HDN_DescState" + i, "$HDN_NumBlob" + i ]); }
Tests:
tail
function objectJoin(data) { var keys = data.keys function tailMap(arr) { if (!arr.length) return [] const [head, ...tail] = arr return [ Object.fromEntries(keys.map((_, i) => [keys[i], head[i]])), ...tailMap(tail) ] } return tailMap(data.values) } objectJoin(testData)
jimmy reduce
var customReduce = data => { var keys = data.keys; return data.values.map(x => { return x.reduce((acc, curr, i) => { acc[keys[i]] = curr; return acc; }, {}) }) } customReduce(testData)
tail 2
function objectJoin(data) { var keys = data.keys function tailMap(arr) { if (!arr.length) return [] const [head, ...tail] = arr return [ keys.reduce((acc, act, i) => { acc[act] = head[i] return acc }), ...tailMap(tail) ] } return tailMap(data.values) } objectJoin(testData)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
tail
jimmy reduce
tail 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):
Measuring the performance of JavaScript functions can be a fascinating topic, and MeasureThat.net provides an excellent platform for doing so. **Benchmark Definition:** The benchmark definition represents a JavaScript function that takes in some data as input. In this case, the data is an object with two properties: `keys` and `values`. The function's purpose is to join these two arrays together into a single array of objects, where each object has a key-value pair for each element in the `keys` array. There are three different approaches implemented in the benchmark definition: 1. **tail**: This approach uses a recursive function called `tailMap` to iterate through the `values` array and create an object with the desired key-value pairs. The key is generated by mapping over the `keys` array, and the value is set to the corresponding element from the `values` array. **Pros:** * Easy to understand and implement * Uses a simple and efficient algorithm **Cons:** * Recursive function calls can lead to stack overflow errors for large inputs * May not be as performant as other approaches due to the overhead of recursive function calls 2. **jimmy reduce**: This approach uses the Array.prototype.reduce() method to iterate through the `values` array and create an object with the desired key-value pairs. The key is generated by mapping over the `keys` array, and the value is set to the corresponding element from the `values` array. **Pros:** * More efficient than the recursive approach for large inputs * Uses a built-in JavaScript function that is optimized for performance **Cons:** * May require additional dependencies (e.g., Lodash) if not using Array.prototype.reduce() * Can be more complex to understand and implement for those unfamiliar with reduce() 3. **tail 2**: This approach uses another implementation of the `tailMap` function, which is identical to the first approach. **Pros:** * Same as tail approach **Cons:** * Duplicate implementation * May not provide a significant performance advantage over the other two approaches In terms of performance, the `jimmy reduce` approach is likely to be the fastest due to its use of Array.prototype.reduce(). However, this may come at the cost of additional dependencies and complexity. The **tail** approach is a simple and easy-to-understand implementation, but it may not be as performant for large inputs. The **tail 2** approach duplicates the implementation of the first approach, so it's unlikely to provide any significant benefits. **Other considerations:** * The benchmark uses Chrome 83 as the browser, which may affect performance. * The input data is generated using a loop that pushes arrays into the `values` array, which can lead to slow performance due to the overhead of creating new objects. If you're looking for alternatives, MeasureThat.net provides a range of other benchmarks and test cases that you can use to compare the performance of different JavaScript functions. Additionally, there are many other online resources available that provide benchmarking tools and libraries, such as Benchmark.js or Microbenchmark.
Related benchmarks:
FieldeasReduce
FieldeasReduce2
FieldeasReduce6
Lodash cloneDeep vs JSON Clone vs Ramda Clone for big Array
Comments
Confirm delete:
Do you really want to delete benchmark?