Skip to content

Commit 6d97885

Browse files
author
LAPTOP-465HP6VI\Victor
committed
Add usage examples to readme and some future ideas
1 parent 7c1127d commit 6d97885

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

RadixSort.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// TODO: Remove extract digit function and just inline the core code. I've seen this improve performance in C#. Not sure how agressively JavaScript inlines small functions.
22
// TODO: Compare performance versus TimSort for random, pre-sorted and constant, since TimSort is available in JavaScript thru npm
33
// (https://stackoverflow.com/questions/40721767/what-is-the-fastest-way-to-sort-a-largeish-array-of-numbers-in-javascript)
4+
// TODO: Compare performance with the following:
5+
// var numArray = new Uint32Array([140000, 104, 99]);
6+
// numArray = numArray.sort();
7+
// alert(numArray)
8+
// TODO: Consider handling these cases as JavaScript .sort does
9+
// array = [3, 5, -1, 1, NaN, 6, undefined, 2, null]
10+
// array.sort((a,b) => isNaN(a) || a-b)
11+
// [-1, null, 1, 2, 3, 5, 6, NaN, undefined]
412

513
var HpcAlgorithms = HpcAlgorithms || {};
614

readme.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,21 @@ Discussion, benchmarks and usage in https://duvanenko.tech.blog/2017/06/15/faste
1313
This is a stable sort, while JavaScript built-in is not stable. This sort algorithm is not in-place, returning a new sorted array.
1414
Discussion, benchmarks and usage in https://duvanenko.tech.blog/2017/07/10/sorting-arrays-of-objects-in-javascript-with-radix-sort/
1515

16-
When you benchmark these algorithms keep in mind that for the first one or two runs a basic JavaScript compiler is used, providing fast
17-
time to start up and to give time for the full optimizing compiler to run. After these two runs optimized code starts being used,
18-
revealing the full performance of LSD Radix Sort. See https://blog.sessionstack.com/how-javascript-works-inside-the-v8-engine-5-tips-on-how-to-write-optimized-code-ac089e62b12e
16+
When you benchmark these algorithms keep in mind that for the first few runs the basic JavaScript JIT compiler is used, providing fast
17+
start up time and giving time for the optimizing compiler to run. After these few runs the optimized code starts being used,
18+
revealing the full performance of LSD Radix Sort algorithms. See https://blog.sessionstack.com/how-javascript-works-inside-the-v8-engine-5-tips-on-how-to-write-optimized-code-ac089e62b12e
1919
for more details about the JIT engine in Chrome.
2020

21-
If you have a specific needs for higher performance algorithms, let us know.
21+
# Examples
22+
23+
```javascript
24+
function simpleUsageExampleOfRadixSortLSD() {
25+
var arrayToBeSorted = [ 99, 1999999999, 51, 23, 102];
26+
var sortedArray = HpcAlgorithms.Sorting.RadixSortLsdUInt32(arrayToBeSorted);
27+
for ( var _current = 0; _current < sortedArray.length; _current++ ) {
28+
console.log(sortedArray[_current]);
29+
}
30+
}
31+
```
32+
33+
If you have other specific needs for higher performance algorithms, let us know.

0 commit comments

Comments
 (0)