Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Sorting of array
(version: 0)
Comparing performance of:
Built in sort vs Insertion sort
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const list = [20, 10, 50, 33, 1, 5, 90, 45, 39, 77, 11]; function built_in_sort(arr) { return arr.sort((a, b) => a - b); } //Insertion sort function insertion_sort(ary) { for (var i = 1, l = ary.length; i < l; i++) { var value = ary[i]; for (var j = i - 1; j >= 0; j--) { if (ary[j] <= value) break; ary[j + 1] = ary[j]; } ary[j + 1] = value; } return ary; }
Tests:
Built in sort
built_in_sort([20, 10, 50, 33, 1, 5, 90, 45, 39, 77, 11])
Insertion sort
insertion_sort([20, 10, 50, 33, 1, 5, 90, 45, 39, 77, 11])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Built in sort
Insertion sort
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Built in sort
3511558.2 Ops/sec
Insertion sort
17980036.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark is comparing two sorting algorithms: built-in JavaScript sort and insertion sort. The script preparation code defines both algorithms: 1. `built_in_sort`: This function uses the built-in JavaScript `sort()` method with a custom comparison function `(a, b) => a - b`. 2. `insertion_sort`: This function implements a standard insertion sort algorithm. **Options compared** The benchmark is comparing two options: 1. **Built-in JavaScript sort**: Uses the built-in `sort()` method with a custom comparison function. 2. **Insertion sort**: A standard sorting algorithm implemented from scratch. **Pros and Cons of each approach** * **Built-in JavaScript sort**: + Pros: Fast, efficient, and widely supported across browsers. + Cons: May not be suitable for small arrays or specific use cases where a custom comparison function is required. * **Insertion sort**: + Pros: Simple to implement, stable, and suitable for small arrays or specific use cases. + Cons: Generally slower than built-in sorting algorithms, especially for large datasets. **Library/dependency** The `sort()` method in JavaScript uses the `compare()` function from the `Array.prototype` object. This is a standard library function that performs a comparison between two elements and returns a value indicating their order. **Special JS feature/syntax** There is no special JavaScript feature or syntax being used in this benchmark. The focus is on comparing two existing sorting algorithms. **Other alternatives** If you want to include more sorting algorithms in your benchmark, here are some alternatives: 1. **Merge sort**: A divide-and-conquer algorithm that's efficient and stable. 2. **Quick sort**: Another divide-and-conquer algorithm that's fast but may not be as stable as merge sort. 3. **Heap sort**: An in-place sorting algorithm that's simple to implement but generally slower than other algorithms. 4. **Radix sort**: A non-comparative sorting algorithm that's efficient for large datasets of integers or strings. These alternatives can provide a more comprehensive understanding of different sorting algorithms and their performance characteristics. **Benchmark preparation code** The provided JSON includes the script preparation code, which defines both the built-in JavaScript `sort()` method and the insertion sort algorithm. This allows the benchmark to execute these algorithms with identical input data. **Individual test cases** Each individual test case compares a specific scenario: 1. **Built-in sort**: The built-in JavaScript `sort()` method is executed on an array of 11 elements. 2. **Insertion sort**: The insertion sort algorithm is implemented from scratch and executed on the same array of 11 elements. By comparing these two algorithms, we can understand their performance characteristics and determine which one might be more suitable for specific use cases or scenarios.
Related benchmarks:
Javascript Sorting Algorithmzzz
Javascript native sort vs quick-insertion-sort
Test Quick Insertion Sort3
native sort vs insertion vs selection
Comments
Confirm delete:
Do you really want to delete benchmark?