Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Nathanjamals sorting test
(version: 0)
Comparing performance of:
obj and array methods vs old school
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
obj and array methods
const FACET_PRIORITY = ['trim', 'body', 'color', 'fueltype', 'cc', 'gearbox', 'seats', 'doors']; const descriptorParts = { trim: 'S Line', color: 'beiges', doors: '5 door' }; const descriptorOrdered = ['audi A1']; const sortedExtraFacets = Object.keys(descriptorParts) .sort((a, b) => FACET_PRIORITY.indexOf(a) - FACET_PRIORITY.indexOf(b)) .map((key) => descriptorParts[key]); return [...descriptorOrdered,...sortedExtraFacets];
old school
const FACET_PRIORITY = ['trim', 'body', 'color', 'fueltype', 'cc', 'gearbox', 'seats', 'doors']; const descriptorParts = { trim: 'S Line', color: 'beiges', doors: '5 door' }; const descriptorOrdered = ['audi A1']; for (const facetKey of FACET_PRIORITY) { if (descriptorParts[facetKey]) { descriptorOrdered.push(descriptorParts[facetKey]); } } return descriptorOrdered;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
obj and array methods
old school
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
obj and array methods
4517249.0 Ops/sec
old school
11701103.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark JSON and explain what's being tested. **Benchmark Definition** The `benchmark definition` is an object that describes the test case. In this case, there are two test cases: 1. "obj and array methods" 2. "old school" **Test Cases** Let's analyze each test case: ### obj and array methods This test case uses JavaScript objects and arrays. The benchmark definition includes: * `descriptorParts`: an object with string values (e.g., "S Line", "beiges") * `FACET_PRIORITY`: an array of strings that defines the order of sorting * `descriptorOrdered`: an array that initially contains a single value ("audi A1") * The test code sorts the keys of `descriptorParts` based on their index in `FACET_PRIORITY`, maps each key to its corresponding value, and then pushes these values onto `descriptorOrdered` The goal is to measure how quickly this code executes. **Pros and Cons** Using an object with a sorted array of keys can be efficient because it allows for fast lookups and sorting. However, the use of `Object.keys()` and `sort()` might incur additional overhead due to the way JavaScript handles objects and arrays. In contrast, the "old school" approach uses a simple `for` loop to iterate over the `FACET_PRIORITY` array and push values onto `descriptorOrdered`. This approach can be faster in certain cases because it avoids the overhead of object methods like `sort()`. **Old School Approach** The "old school" approach is likely using an older JavaScript syntax, possibly from a previous version or a specific library. In this case, it's using a `for...of` loop to iterate over the array and push values onto the `descriptorOrdered` array. This approach can be faster because it: * Avoids the overhead of creating an object with a sorted array of keys * Uses a simple iteration that doesn't involve object methods like `sort()` * Is likely to be more efficient in terms of memory usage However, this approach may not work as expected if the input data is large or complex. **Library and Special JS Features** There are no libraries mentioned in the benchmark definition. However, some JavaScript features might be used: * `Object.keys()` and `sort()`: built-in JavaScript methods * `for...of` loop: a feature introduced in ECMAScript 2015 (ES6) The "old school" approach uses a feature that is no longer supported in modern browsers. **Other Alternatives** If the benchmark author wants to compare other approaches, they could consider adding more test cases with different algorithms or data structures. For example: * Using an array of objects instead of an object with sorted keys * Using a different sorting algorithm, such as quicksort or mergesort * Adding noise or randomness to the input data to simulate real-world scenarios Some possible alternatives for the "obj and array methods" test case could be: * Using a `Set` instead of an object to store unique values * Using a more efficient sorting algorithm like heap sort or radix sort * Adding randomization to the input data to simulate varying performance characteristics
Related benchmarks:
Sorting speed comparison
pre-sorted sorting (int vs obj)
arr.sort((a, b) => a - b)[0] vs. Math.min(...arr)
Sort method comparisons (quicksort, for loop, Arra.prototype.sort)
sorting an array and then reverse vs sorting with reversive comparison
Comments
Confirm delete:
Do you really want to delete benchmark?