Scientific Computing on an M1 MacBook Air

Chris
3 min readDec 12, 2020
Woman using an Apple laptop.
Photo courtesy of Ekaterina Bolovtsova

Santa arrived early in 2020 and delivered a new MacBook Air with an M1 CPU. It’s the base model (7 GPU cores, not 8) upgraded to 16 GB RAM. It replaces a 2017 MacBook Pro. I bought the Air for the speed upgrade, and to hedge against losing value in the Pro — to sell it at a time of year when people may be looking to buy gifts or another screen for Netflix or Zoom calls.

Why didn’t I buy the M1 MacBook Pro? Because the M1 chip is essentially identical between these machines, and the Pro is meaningfully more expensive. The main difference I might care about is that the Pro has a fan to cool the CPU, while the Air just slows the CPU down a little instead. That’s a trade-off that I can live with.

I’m a statistician, and I’ve spent too much of my life already waiting for computers to finish computing, so I was excited to learn how much time I may be able to save (or more realistically, spend on yet more computation). I decided to do a very unscientific, n=1 comparison, between the Pro and the Air, timing how long the two machines took to run exactly the same analysis.

The analysis in question is a meta-analysis written in a mix of Stata and Stan (the latter is a system for compiling Bayesian models written in a C-like language to C++, and from that to an executable binary). In brief, we’re trying to identify risk factors that predict pain after knee replacement surgery. The analysis involves reading in a few small data sets, doing some relatively simple data manipulation, running some meta-analyses in Stata, several runs of a moderately-complex Stan model, making lots of figures, combining them into a Word document, and then finally compiling a PDF preprint using LaTeX. Most of the time goes into running the Stan model and making the figures.

I added basic timing code to the analysis and ran it on the two machines. All generated files are tracked in git, which means it’s trivial to test that the two systems produce exactly the same results (they did!). So, which machine is fastest?

The Pro took 964 seconds (about 16 minutes), while the Air took 517 seconds (about 8½ minutes). In this case the Air was about 1.9 times faster than the Pro. I don’t feel compelled to run the analyses multiple time to put a statement of uncertainty on this comparison (there are better things to spend my time and electricity on). However, an almost factor of two speed-up is fantastic.

And heres’s the kicker: while I upgraded Stata to a version compiled for the M1 chip, I wasn’t able to get Stan to compile my model for the M1. I therefore ran the intel x86 version of the model under Rosetta 2. In other words, once the Stan developers (or I!) figure out how to compile Stan models to run natively on the M1, I would expect this analysis to run even faster.

--

--