Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Function Comparison
(version: 0)
Comparing performance of:
Function A vs Function B
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
function formatNode(data) { return data.map(row => { const { id, label, ...properties } = row; return { id, label, properties: _.mapValues(properties, v => _.first(v)) }; }); } function format(data) { return data.map(row => formatt(row)) } function formatt({id, label, ...properties}) { return { id, label, properties: _.mapValues(properties, v => _.first(v)) } }
Tests:
Function A
const input = [{ id: 1, label: 'label 1', property_1: ['prop_1'], property_2: ['prop_2'] }, { id: 2, label: 'label 2', property_3: ['prop_3'], property_4: ['prop_4'] } ] const funcA_res = formatNode(input)
Function B
const input = [{ id: 1, label: 'label 1', property_1: ['prop_1'], property_2: ['prop_2'] }, { id: 2, label: 'label 2', property_3: ['prop_3'], property_4: ['prop_4'] } ] const functB_res = format(input)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Function A
Function B
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 the provided benchmark and explain what's being tested. **Benchmark Definition** The benchmark definition is a JSON object that contains information about the test case. The script preparation code defines two functions: * `formatNode(data)`: This function takes an array of objects as input, where each object has properties like `id`, `label`, and others. It maps over the array, extracts the `id` and `label` from each object, and returns a new array with these values modified by taking the first value of their respective property arrays (e.g., `property_1: ['prop_1']` becomes `{ id: 1, label: 'label 1', properties: ['prop_1'] }`). The function uses the `_` object from Lodash. * `format(data)`: This function is similar to `formatNode`, but it doesn't take any input parameters and calls the internal implementation of `formatNode`. The HTML preparation code includes a script tag that loads the Lodash library. **Individual Test Cases** There are two test cases: 1. **Function A**: This test case defines an input array `input` with two objects, each with properties like `id`, `label`, and others. It calls the `formatNode(input)` function to execute this code. 2. **Function B**: This test case is similar to Function A, but it calls the internal implementation of `formatNode` directly instead of passing it as a parameter. **What's Being Tested** These two functions are being compared to measure their performance difference. Specifically: * We're interested in how many executions per second each function can perform. * The test case uses Lodash for array manipulation, which introduces an additional overhead. **Options Compared** There are two options being compared: 1. **Function A**: Calls the external `formatNode` function with input parameters. 2. **Function B**: Calls the internal implementation of `formatNode`. **Pros and Cons** * **Function A (External Call)**: + Pros: Reuses existing code, might be easier to maintain or extend. + Cons: Introduces an additional overhead due to the external function call. * **Function B (Internal Call)**: + Pros: Eliminates the overhead of the external function call. + Cons: Might require more boilerplate code and maintenance. **Lodash Library** The Lodash library is used for array manipulation in both test cases. It provides utility functions like `_mapValues` to extract the first value from an object's property arrays. **Special JS Feature/Syntax** There doesn't seem to be any special JavaScript feature or syntax being tested here. The code uses standard ES6 syntax and Lodash library. **Other Alternatives** If you wanted to rewrite these test cases using a different approach, some alternatives could include: * Using a custom implementation of the `formatNode` function without relying on Lodash. * Replacing the external call with an inlined version of the function, which might introduce performance benefits but increases code size and complexity. Please note that rewriting these test cases would likely alter their behavior or performance characteristics, so it's essential to consider the specific requirements and constraints before making changes.
Related benchmarks:
Function Comparison 2
Function Comparison 2.1
Lodash MapValue vs Pure JS
Lodash MapValue vs Pure JS [2.0]
Comments
Confirm delete:
Do you really want to delete benchmark?