Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Javascript Sort (numbers/strings)
(version: 0)
Port from jsperf(https://jsperf.com/sorting-algorithms/58)
Comparing performance of:
Built-in Sort (numbers) vs Built-in Sort (strings)
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script> function number_sort(ary) { return ary.sort(function(a, b) { return a - b; }); } function string_sort(ary) { return ary.sort(function(a, b) { return a.localeCompare(b); }); } </script>
Script Preparation code:
var numbers = []; for (var i = 0; i < 10000; i++) { numbers[i] = Math.round(Math.random() * 1000000); } var strings = []; for (var i = 0; i < 10000; i++) { strings[i] = Math.round(Math.random() * 1000000).toString(); }
Tests:
Built-in Sort (numbers)
number_sort(numbers.slice(0));
Built-in Sort (strings)
string_sort(strings.slice(0));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Built-in Sort (numbers)
Built-in Sort (strings)
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0
Browser/OS:
Firefox 125 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Built-in Sort (numbers)
1069.8 Ops/sec
Built-in Sort (strings)
56.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** The provided JSON represents a JavaScript benchmark test case on MeasureThat.net. The benchmark measures the performance of two built-in sorting functions in JavaScript: `sort()` for numbers and `localeCompare()` for strings. **Script Preparation Code** The script preparation code generates two arrays, `numbers` and `strings`, each containing 10,000 random integers or strings between 0 and 1,000,000. These arrays are used as input to the sorting functions being benchmarked. **Html Preparation Code** The HTML preparation code defines two JavaScript functions: `number_sort()` and `string_sort()`. These functions use the built-in `sort()` method for numbers and `localeCompare()` method for strings, respectively. The `slice(0)` method is used to create a shallow copy of the input arrays. **Individual Test Cases** There are two individual test cases: 1. **Built-in Sort (numbers)**: This test case measures the performance of the built-in sorting function on the `numbers` array. 2. **Built-in Sort (strings)**: This test case measures the performance of the built-in sorting function on the `strings` array. **Options Compared** The two options being compared are: 1. **Built-in Sort**: The built-in `sort()` method, which is a part of the JavaScript standard library. 2. **Custom Implementation**: A custom implementation of the sorting algorithm (not shown in the code snippet). **Pros and Cons of Built-in Sort** * Pros: + Fast execution speed + Robust and reliable + Part of the JavaScript standard library, so widely supported * Cons: + May not be optimal for specific use cases or data types + Can be slower than custom implementations for certain input sizes or distributions **Pros and Cons of Custom Implementation** * Pros: + May be optimized for specific use cases or data types + Can be faster than built-in sort for large input sizes or complex sorting algorithms * Cons: + Requires additional implementation effort + May not be as robust or reliable as built-in sort **Library and Purpose** The `localeCompare()` method is a part of the JavaScript standard library, specifically introduced in ECMAScript 5 (ES5). It compares two strings using their locale-specific collation rules. **Special JS Feature or Syntax** There are no special JS features or syntax used in this benchmark. The code only uses standard JavaScript language constructs and built-in methods. **Other Alternatives** Some alternative sorting algorithms that could be compared in a benchmark include: 1. **Quicksort** 2. **Merge Sort** 3. **Heap Sort** 4. **Radix Sort** (for large datasets or specific data types) 5. **Custom sorting algorithms**, such as insertion sort, bubble sort, or tree-based sorts. These alternatives could be used to compare their performance against the built-in `sort()` method and custom implementation in a benchmark test case like this one.
Related benchmarks:
Javascript Sorting Algorithmzzz
Javascript Sort
Javascript Sorting Algorithms (weird sort)
Javascript Sorting Algorithms Test
Comments
Confirm delete:
Do you really want to delete benchmark?