Text & documents
Numbers & maths
Data & formats
Security
Development & DevOps
Artificial Intelligence
Finance
Health & Wellness
Productivity
Games & Entertainment
Multimedia & design
Business
How to use
Your code, counted

Write a function sort(a) that sorts the array a in place, or start from a template. It runs in your browser, apart from the page and with an 8-second limit, on arrays of 8 to 1024 elements that are already sorted, reversed and random. Your code does not need any changes to be counted: every time you compare two elements with <, > or by subtracting them, that is one comparison; every a[i] is a read and every a[i] = … a write.

How it grows

With the large sizes, the tool tests which curve best fits your counts: n, n log n or n², and with what constant (“≈ 0.5·n²”). It is a measurement, not a proof: an algorithm can look n log n at these sizes and not be.

Stability

A sort is stable if two elements with the same key stay in the order they came in. The tool checks it with an array full of repeated keys that remember their original position.

What is not counted

Comparisons with === (they do not call valueOf) and whatever you do in auxiliary arrays, except when you write back into a. Comparing an element with a plain number counts as half a comparison.

AlgorithmsYour code counted, the table filling in and pruning in plain sight
AlgorithmsYour code counted, the table filling in and pruning in plain sight

Write your sort (or start from a template) and see how much work it really does: comparisons, reads and writes, on arrays of 8 to 1024 elements.

Your code