F# – Simple QuickSort implementation

For illustration purposes only, here’s how you can implement the QuickSort algorithm in a few lines of code:

image

Note that I’ve not made the list generic to avoid complications and performance overheads associated with dealing with generics. Even then, my 5-line implementation pales in comparison with the built-in sort function:

image

This just goes to show how good the built-in functions are Winking smile!

In case you’re wondering how a generic version of my QuickSort implementation would do in comparison, here’s the results:

image

image

Generic equality or comparison is pretty slow, so where possible (not in this case unfortunately) you should mark functions that requires generic comparison ‘inline’ to boost performance.

Enjoy what you’re reading? Subscribe to my newsletter and get more content on AWS and serverless technologies delivered straight to your inbox.


Yan Cui

I’m an AWS Serverless Hero and the author of Production-Ready Serverless. I have run production workload at scale in AWS for nearly 10 years and I have been an architect or principal engineer with a variety of industries ranging from banking, e-commerce, sports streaming to mobile gaming. I currently work as an independent consultant focused on AWS and serverless.

You can contact me via Email, Twitter and LinkedIn.

Hire me.


Check out my new course, Complete Guide to AWS Step Functions.

In this course, we’ll cover everything you need to know to use AWS Step Functions service effectively. Including basic concepts, HTTP and event triggers, activities, design patterns and best practices.

Get Your Copy