Multithreaded Memset

Chris
1 min readApr 9, 2023

Introduction

I was writing some code and, as I often do, I needed to use memset and a thought occurred to me that there would likely be some size threshold where a multithreaded memset would be faster. I wasn’t interested in securely setting it to zero, I wanted to leave the optimiser to do the best job it could without discarding the code entirely and see what the results might be. The processor on my machine is a 1950x Threadripper on Windows and it using 32 threads to memset. Your results will almost certainly differ wildly. Code is available here.

The Test

I was quite sure there would be a crossover threshold where multithreaded memset would be faster, but I wasn’t quite expecting it to look like this. This graph shows that, at least one my machine and for certain sizes of memset, it is sometimes faster to multithreaded memset more memory.

Discord Monocle Twitter

--

--