Speeding up your code when multiple cores aren’t an option
The common advice when Python is too slow is to switch to a low-level compiled language like Cython or Rust. But what do you do if that code is too slow? At that point you might start thinking about parallelism: using multi-threading or multi-processing so you can take advantage of multiple CPU cores. But parallelism comes with its own set of complexities; at the very least, some algorithms can only really work in a single-threaded way. So what can you do? As it turns out, there’s often still plenty of performance improvements you can get just by tweaking your low-level code. As a real-world example, in this article we’ll go about optimizing Floyd-Steinberg error diffusion dithering. The specific variant of the algorithm that we will implement converts a grayscale image with values of 0 to 255 into an image with just two colors, black and white. Because of the specifics of this algorithm, it’s quite difficult or perhaps even impossible to parallelize with threading. But you can still m
Speeding up your code when multiple cores aren’t an option Speeding up your code when multiple cores aren’t an option by Itamar Turner-Trauring Last updated 21 Sep 2023, originally created 20 Sep 2023 The common advice when Python is too slow is to switch to a low-level compiled language like Cython or Rust. But what do you do if that code is too slow? At that point you might start thinking about parallelism: using multi-threading or multi-processing so you can take advantage of multiple CPU cores. But parallelism comes with its own set of complexities; at the very least, some algorithms can o
Explore this link on the map →related reading
- Making Deep Learning go Brrrr From First Principleshorace.io
- abseil / Performance Hintsabseil.io
- Algorithms for Modern Hardware - Algorithmicaen.algorithmica.org
- GitHub - stanford-cs149/asst1: Stanford CS149 -- Assignment 1 · GitHubgithub.com
- A Parallel Computing Primerthephysicsmill.com
- Amdahl's law - Wikipediaen.wikipedia.org
- Multi Core Programming and Threadsimomath.com
- the unreasonable effectiveness of dithering | Jonathan Dobresjdobr.es
- Infographics: Operation Costs in CPU Clock Cycles - 6IT6it.dev
- Rust Optimization.md · GitHubgist.github.com
- abseil / Performance Hintsabseil.io
- Modern Python performance considerations [LWN.net]lwn.net