Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test Sorting Locations etc etc etc
(version: 0)
Comparing performance of:
Itself vs sorted
Created:
3 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:
const locations = [{ "value": "AF", "label": "Afghanistan", "unit": "country" }, { "value": "AR", "label": "Argentina", "unit": "country" }, { "value": "522", "label": "Columbus, GA", "unit": "dma" }, { "value": "KY", "label": "Cayman Islands", "unit": "country" }, { "value": "AO", "label": "Angola", "unit": "country" }, { "value": "AG-03", "label": "Antigua and Barbuda, Parish of Saint George", "unit": "region" }, { "value": "AE-AZ", "label": "United Arab Emirates, Abu Dhabi", "unit": "region" }, { "value": "821", "label": "Bend, OR", "unit": "dma" }, { "value": "AL-02", "label": "Albania, Qarku i Durresit", "unit": "region" }, { "value": "757", "label": "Boise, ID", "unit": "dma" } ] function itself () { return locations } function sortWithLodash() { const testSort = locations.reduce((acc, next) => { acc[next.unit].push(next) return acc }, { country: [], region: [], dma: [] }) const sortedCountry = _.sortBy(testSort.country, 'label') const sortedRegion = _.sortBy(testSort.region, 'label') const sortedDma = _.sortBy(testSort.dma, 'label') return sortedCountry.concat(sortedRegion).concat(sortedDma); }
Tests:
Itself
itself();
sorted
sortWithLodash();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Itself
sorted
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, compared, and their pros/cons. **Benchmark Overview** The benchmark consists of two test cases: `Itself` and `sorted`. The benchmark is designed to measure the performance of JavaScript functions that sort an array of objects. The array contains locations with different units (country, region, dma). **Script Preparation Code** The script preparation code defines a constant `locations` containing an array of location objects: ```javascript const locations = [...] ``` Each location object has three properties: `value`, `label`, and `unit`. **Function Definitions** Two functions are defined: 1. `itself()`: Returns the `locations` array as is. 2. `sortWithLodash()`: Sorts the `locations` array using Lodash's `sortBy()` function, grouping by unit, and returns a concatenated sorted array. **Html Preparation Code** The HTML preparation code includes a reference to the Lodash library: ```html <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> ``` This suggests that the benchmark will run in a browser environment, and the Lodash library is used for sorting. **Comparison** The two test cases are compared: 1. `Itself`: Measures the performance of simply returning the `locations` array as is. 2. `sorted`: Measures the performance of sorting the `locations` array using `sortWithLodash()`. **Pros and Cons** **Itself:** Pros: * Simple, straightforward implementation * Requires minimal overhead Cons: * Returns an unsorted array, which may not be representative of real-world scenarios **sorted:** Pros: * Uses a well-known library (Lodash) for sorting * Groups by unit, which might be more representative of real-world scenarios Cons: * Requires the Lodash library, adding overhead * The `sortWithLodash()` function is specific to Lodash and may not be easily translatable to other libraries or implementations **Other Considerations** The benchmark uses a fictional device platform (Macintosh; Intel Mac OS X 10_15_7) and operating system (Mac OS X 10.15.7). The `ExecutionsPerSecond` metric suggests that the benchmark is designed to measure performance in terms of how many iterations can be executed per second. **Alternatives** If you wanted to write a similar benchmark, you could consider using: * Other sorting libraries (e.g., built-in JavaScript sort(), or other libraries like FastSort or Timsort) * Custom sorting implementations (e.g., using a simple bubble sort or insertion sort algorithm) * Different data structures (e.g., arrays, objects, or more complex data structures) Keep in mind that the specific implementation and comparisons will depend on your goals and requirements.
Related benchmarks:
Filter or Reduce vs Loop
tickets
find vs some for objects
for... of vs find
Comments
Confirm delete:
Do you really want to delete benchmark?