# Parallel sort

**URL:** <https://forum.crystal-lang.org/t/parallel-sort/6454>\
**Category:** Crystal Contrib\
**Created:** [January 31, 2024, 12:15pm UTC](https://forum.crystal-lang.org/t/parallel-sort/6454 "2024-01-31T12:15:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [January 31, 2024, 12:15pm UTC](https://forum.crystal-lang.org/t/parallel-sort/6454/1 "2024-01-31T12:15:14Z")

</div>

Found this on Mastodon:

> **[Comparing Standard Library Sorts: The Impact of Parallelism](https://chapel-lang.org/blog/posts/std-sort-performance/)**
>
> This blog post compares the performance of standard library sort routines in several programming languages.

There are also some interesting comments in this thread:

> **[mppf (@mppf@hachyderm.io)](https://hachyderm.io/@mppf/111847430274880297)**
>
> Attached: 1 image
> 
> I've created a #blog post comparing the performance of standard library 'sort' calls in different languages. Chapel's sort uses composable parallelism to be 10x faster than other popular languages for a test sort on my...

Would be nice to have a parallel sorting algorithm in Crystal as well, seems to be well worth it 😏

---

<div class="post-metadata">

**Author:** ![jgaskins](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/jgaskins/32/2449_2.png) [@jgaskins](https://forum.crystal-lang.org/u/jgaskins)\
**Post date:** [February 1, 2024, 1:37am UTC](https://forum.crystal-lang.org/t/parallel-sort/6454/2 "2024-02-01T01:37:22Z")

</div>

Maybe. The blog post presents a pathological example that _rarely_ occurs in reality in any programming language — sorting an array of size 128M in memory with gobs of CPU cores available to a single process that are otherwise doing nothing.

Generally speaking, I follow 2 rules of thumb regarding parallelization of a single unit of work:

1. It’s usually worth it to parallelize spiky workloads because you have a lot of available CPU time that you can actually put to use, but high-baseline workloads don’t make sense to parallelize — you’re already using those CPU cores
2. It’s almost always worth it to parallelize large workloads, but almost never worth it to parallelize smaller workloads — the cost of parallelization needs to be amortized by the reduced latency of the workload

---

<div class="post-metadata">

**Author:** ![jzakiya](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/jzakiya/32/278_2.png) [@jzakiya](https://forum.crystal-lang.org/u/jzakiya)\
**Post date:** [February 1, 2024, 3:43am UTC](https://forum.crystal-lang.org/t/parallel-sort/6454/3 "2024-02-01T03:43:44Z")

</div>

I had never heard of Chapel. So doing a little research I came across the below items where someone questioned the comparison of Chapel with Rust for the sort algorithm.

One of my enduring hopes is that Crystal will also (soon) develop a true parallel processing implementation (not based on fibers) to truly compete in the field of highly parallel arithmetic and numerical algorithms.

> **[Comparing Standard Library Sorts: The Impact of Parallelism](https://chapel.discourse.group/t/comparing-standard-library-sorts-the-impact-of-parallelism/30411)**
>
> This topic is a place to discuss the blog post on sorting available here: Comparing Standard Library Sorts: The Impact of Parallelism

> <https://github.com/chapel-lang/chapel/pull/24302>
>
> On my machine, Rust has almost the same performance now. Please update your blog… post for a better comparison.
> 
> Why would you use the \`rand\` crate for random number generation and not \`rayon\` for parallelism?
> 
> \`rayon\` is written in 100% Rust. About the "Standard library" thing: Rust by design keeps its standard library as small as possible. Major crates like \`rayon\` are often maintained by the Rust maintainers themself. For \`rayon\`, the two main maintainers Josh Stone and Niko Matsakis are core Rust contributors. Niko is even a team leader of the language team: https://www.rust-lang.org/governance

[![](https://img.youtube.com/vi/QiyLkfYHEvg/maxresdefault.jpg "Intro to Using Chapel for Parallel Programming: Part 1") ](https://www.youtube.com/watch?v=QiyLkfYHEvg)
