I tried optimizing the function, removing functions call seem to help quite a bit, and prevent stack overflows just a bit since it is easy to get one.
qsort: 165526.5649749999865889 (0.398799999995389953255)
swap and qsort_partition not needed anymore:
// Quick sort Array.prototype.qsort = function (left, right) { var pivot, newPivot, pivotVal, tmp; if (left === undefined) { left = 0; right = this.length - 1; } if (left < right) { pivot = left + Math.ceil((right - left) / 2); // Partition pivotVal = this[pivot]; newPivot = left; this[pivot] = this[right]; this[right] = pivotVal; for (var i = left; i < right; i++) { if (this[i] < pivotVal) { tmp = this[i]; this[newPivot++] = i; this[i] = tmp; } } this.qsort(left, newPivot - 1); this.qsort(newPivot + 1, right); } }; Uint16Array.prototype.qsort = Array.prototype.qsort;
@TiCPU started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I tried optimizing the function, removing functions call seem to help quite a bit, and prevent stack overflows just a bit since it is easy to get one.
swap and qsort_partition not needed anymore: