Sorting Performance

notes
performance
Author

Conrad Kay

Published

May 16, 2025

Results are for sorting n random floats generated using Math.random() in Node.js and random.random() in Python 3.12

Python 3.11 introduced Powersort, an improvement on Timsort, but it isn’t that much faster for most cases.

Each result is averaged over 10 consecutive runs with newly randomized arrays each time.

Python was 10-20x slower than NumPy, and Node.js was 2-3x slower than Python

I also tested set creating (new Set(arr) and set(arr)). This is how many times faster creating a set was compared to sorting.

Numpy is skipped since it doesn’t really have sets. There’s set operations, and .unique but that creates a sorted array.

The sorting rabbit hole goes very deep, as does performance and benchmarking, but this is enough that I typically won’t worry about having to sort arrays.