Today’s processors usually have more than one core, but most programs only use one. Often it doesn’t matter, the computer is fast enough as it is. But then you sometimes get into areas where you are annoyed that you can only use one core. Especially with the UNIX commands, which can sometimes exploit several cores as a GNU version, one part of my Mac CPU is bored while the other is 100 percent utilized. My example is about a text file with 8.6 gigabytes (not megabytes :-), which I have to sort and process. What if you could use more than one core?
How many cores does my Mac have anyway? Open Terminal once and then
sysctl -n hw.ncpu
and the number of cores will be spat out. Well, not quite. It is the number of threads. My MacBook Air has a dual-core processor, but it shows 4 cores. And unfortunately, the Mac OS X version of sort can only use one core. Homebrew provides a remedy:
/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
Afterwards
brew update
brew install coreutils
… and you have the GNU version of sort, which can be called with gsort. gsort understands the parameter –parallel=n, so with my four cores…
gsort –parallel=4 datei.txt
And lo and behold, I have over 350% CPU usage Attention: This doesn’t work if gsort is waiting in a pipe for the output of another command.