# Best CPU for RStan/brms

**URL:** <https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808>\
**Category:** General\
**Created:** [March 21, 2023, 12:05am UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808 "2023-03-21T00:05:35Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Longshot408](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/longshot408/32/6484_2.png) [@Longshot408](https://discourse.mc-stan.org/u/Longshot408)\
**Post date:** [March 21, 2023, 12:05am UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/1 "2023-03-21T00:05:35Z")

</div>

Hi all, just a quick question about recommendations for CPU’s. I’m looking into building some new computers for my research lab and I’m having trouble finding benchmarks for CPU’s to help me decide. So far I’ve seen the Chromium Code Compile benchmark in Gamer’s Nexus reviews (e.g., [AMD Ryzen 9 7900X3D CPU Review & Benchmarks: Spoiled by the 5800X3D - YouTube](https://www.youtube.com/watch?v=PA1LvwZYxCM&t=794s)), and the Microsoft Visual Studio C++ benchmark on TechPowerUp ([AMD Ryzen 9 7950X3D Review - Best of Both Worlds - Software & Game Development | TechPowerUp](https://www.techpowerup.com/review/amd-ryzen-9-7950x3d/9.html)). **Are either of these representative of R generally, or running brms models specifically?**

Obviously I can’t go wrong by going as expensive as possible with the Ryzen 7950X3D. But I don’t feel like spending $800 on 16 cores when I’m only running 4-5 chains, and half as many cores will do fine. Wondering what the best balance is between price and performance.

---

<div class="post-metadata">

**Author:** ![franzsf](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/franzsf/32/8545_2.png) [@franzsf](https://discourse.mc-stan.org/u/franzsf)\
**Post date:** [March 21, 2023, 5:30pm UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/2 "2023-03-21T17:30:25Z")

</div>

There are some good posts (perhaps dated) here:

> [@Buying a new computer - best hardware for fast Stan performance](https://discourse.mc-stan.org/t/buying-a-new-computer-best-hardware-for-fast-stan-performance/3349/23):
>
> What makes you sure it’s the L3 cache not the L2? Most Xeons have 1MB L2, i7 256 KB per core.

> [@Buying a new laptop, what should I get?](https://discourse.mc-stan.org/t/buying-a-new-laptop-what-should-i-get/15263/8):
>
> I recently found myself in the unusual situation of having a fairly large budget to buy a new laptop for work, and running Stan models was one of my main drivers for choosing the system specifications. (It’s typically the most demanding thing my laptop has to handle.) To answer the question for people who aren’t looking to buy a MacBook, I followed the advice here and eventually ordered a Thinkpad P1 Gen2 with the Intel Core i9-9880H Processor and 64GB RAM (and an NVIDIA Quadro T2000 GPU). Th…

I think the consensus revolved around (1) high cache (i.e., L3) on the CPU, (2) moar cores, (3) RAM.

I’ve been impressed with the speedups from within-chain parallelization in brms, so even if you’re running 4 chains, additional cores help.

---

<div class="post-metadata">

**Author:** ![Longshot408](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/longshot408/32/6484_2.png) [@Longshot408](https://discourse.mc-stan.org/u/Longshot408)\
**Post date:** [March 21, 2023, 7:06pm UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/3 "2023-03-21T19:06:43Z")

</div>

Thank you!!

The high cache thing is particularly interesting. After seeing that cache made no difference at all in the Chromium code compile benchmarks I thought it wouldn’t matter here either .I guess I should go for AMD’s latest round of X3D chips then.

---

<div class="post-metadata">

**Author:** ![ma-riviere](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ma-riviere/32/11901_2.png) [@ma-riviere](https://discourse.mc-stan.org/u/ma-riviere)\
**Post date:** [March 26, 2023, 11:37am UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/4 "2023-03-26T11:37:21Z")

</div>

I’d be very interested to see a benchmark comparison between the 7950X and the 7950X3D. The 3D cache feels like it could substantially improve Stan’s sampling speed.

And also one vs the 13900K, since it has the same number of threads but more physical cores.

---

<div class="post-metadata">

**Author:** ![Longshot408](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/longshot408/32/6484_2.png) [@Longshot408](https://discourse.mc-stan.org/u/Longshot408)\
**Post date:** [March 26, 2023, 12:34pm UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/5 "2023-03-26T12:34:11Z")

</div>

Same. I’d also like to know how much of a role RAM speed and latency plays; in one Hardware Unboxed video I saw recently, having faster RAM (6000 MHz DDR5) gave between modest and substantial performance uplifts in gaming, depending on the game, for Ryzen 7000 chips.

Shame there’s no real benchmarks I can find anywhere. The suggestion just seems to be “get the fastest, most expensive thing with all the cores, most cache, and highest boost clocks.” Would love to know where the best performance per dollar ends up though…having a hard time justifying $800 for 7950X3D over the cheaper 7900X3D with no data.

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [December 10, 2024, 8:01pm UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/7 "2024-12-10T20:01:46Z")

</div>

> [@franzsf](#):
>
> I’ve been impressed with the speedups from within-chain parallelization in brms

This requires enough memory bandwidth, so the bus speed and caching are critical. This is why the ARM chips are so good for this kind of thing—faster and wider memory/CPU connection.

> [@Longshot408](#):
>
> I’d also like to know how much of a role RAM speed and latency plays;

This depends on how the data’s organized. If you have a model that has 500MB of data and you hit it randomly in the model, that’s going to be a lot of memory pressure due to cache misses. On the other hand, if you have 500MB of data and access it strictly sequentially, it won’t induce a lot of cache misses, but might be a problem with too much parallelism just due to data quantity and bus contention.

> [@Longshot408](#):
>
> The suggestion just seems to be “get the fastest, most expensive thing with all the cores, most cache, and highest boost clocks.”

That’s not a suggestion! On the other hand, cache and CPU tend to grow together on chips and it’s hard to get one without the other. What you’ll find is that if you have 16 CPUs on a traditional front-side bus memory architecture, you’ll be bottlenecked in memory—the 16 CPUs will spend all their time waiting for the memory to take turns merging into the cache, just like a traffic jam merging onto an expressway.

I have a a 4-year old iMac with 8 physical 3.2 GHz Xeon X cores and 64 GB of 2666 MHz DDR4. This is still relatively fast memory, but it bottlenecks at about 4 chains of Stan. That is, running 8 chains in parallel takes almost as long as running 4 chains until they stop then running 4 more. This is all because of memory contention.

---

<div class="post-metadata">

**Author:** ![ssp3nc3r](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ssp3nc3r/32/120_2.png) [@ssp3nc3r](https://discourse.mc-stan.org/u/ssp3nc3r)\
**Post date:** [December 11, 2024, 4:27am UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/8 "2024-12-11T04:27:01Z")

</div>

I think the “suggestion” is also assuming that because someone asked the question they are not satisfied with wall time in fitting their models. On the other hand, many models can fit fast and fine with older compute. So I’d buy based on actual need. If you’re just learning and exploring this can be great. It’s more about once you aren’t satisfied with wall time, understanding the hardware aspects that Bob summarised well.

---

<div class="post-metadata">

**Author:** ![George\_GL](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/george_gl/32/7750_2.png) [@George\_GL](https://discourse.mc-stan.org/u/George_GL)\
**Post date:** [December 30, 2024, 1:01pm UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/9 "2024-12-30T13:01:16Z")

</div>

Hello everyone,

I have four PCs at home from various generations, so I decided to run a task on each and measure the execution time. While this is by no means a definitive test, it should give a general impression of what these CPUs can do with **brms**.

The M1 Air in my test has 16 GB of RAM, the 16-core Ryzen system has 128 GB, and the M4Pro has 24 GB. The data and syntax for running the analysis on your own machine are attached. The data and model are essentially a modified version of those published [here](https://cran.r-project.org/web/packages/brms/vignettes/brms_threading.html).

The single is just letting chain = 1, cores = 1, with the resulting difference being just the lost overhead in computing and putting it all together.

I am particulary impressed with the M4Pro from Apple, as it bests my 12 core monster with 126Gb Ram, all in a portable format.

[benchmark.csv](https://discourse.mc-stan.org/uploads/short-url/rOborHtjnEC2yozHXhn7vgIOVFW.csv) (1.2 MB)  
[benchmark.R](https://discourse.mc-stan.org/uploads/short-url/q0IRygK3BPXukNh0wuBFid1BMIZ.R) (1.3 KB)

 ![Rplot01](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/3X/a/e/aeb919825051ada7da92e321b0e5b32527e32047.png)

Happy New Year!  
G.

---

<div class="post-metadata">

**Author:** ![andre.pfeuffer](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@andre.pfeuffer](https://discourse.mc-stan.org/u/andre.pfeuffer)\
**Post date:** [December 31, 2024, 6:36am UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/10 "2024-12-31T06:36:43Z")

</div>

What are your makefile settings? Have you used some compiler optimization?  
On my 5800H Notebook with 28W power consumption limit and makefile settings  
`CFLAGS+=-fPIC -O3 -mtune=native -march=native -DEIGEN_USE_BLAS -DEIGEN_USE_LAPACKE`  
it runs in 84s, which I haven’t expected to be that fast.

---

<div class="post-metadata">

**Author:** ![George\_GL](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/george_gl/32/7750_2.png) [@George\_GL](https://discourse.mc-stan.org/u/George_GL)\
**Post date:** [January 1, 2025, 9:51pm UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/11 "2025-01-01T21:51:00Z")

</div>

Ah no, just vanilla stuff. The lastest versions of the packages and that is all. I am not familiar with such mods like makefile settings. Should I?

---

<div class="post-metadata">

**Author:** ![andre.pfeuffer](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@andre.pfeuffer](https://discourse.mc-stan.org/u/andre.pfeuffer)\
**Post date:** [January 2, 2025, 6:17am UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/12 "2025-01-02T06:17:02Z")

</div>

Speed up is significant as shown here:

> [@Speedup by using external BLAS/LAPACK with CmdStan and CmdStanR/Py](https://discourse.mc-stan.org/t/speedup-by-using-external-blas-lapack-with-cmdstan-and-cmdstanr-py/25441/31):
>
> @Bob_Carpenter asked whether the above mentioned flags need to defined when building CmdStan, or is it sufficient to give them only when compiling the model. I tested this, and it is sufficient to define them at the model compilation time. It is not yet completely clear whether there could be speedup, e.g., in $cmdstan\_summary() if those options would be used already when building CmdStan. The current CmdStanR documentation did not have an example how to add flags with += in the compile method,…

It’s also important to know the compiler version, operating system and system.  
Adding `CFLAGS+=-fPIC -O3 -mtune=native -march=native` in file `make/local`  
forcing a rebuild if Stan with `cmdstand_rebuild()` or similar in other environments should be sufficient.

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [January 5, 2025, 7:09pm UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/13 "2025-01-05T19:09:02Z")

</div>

It’s so nice to see a concrete report. Thanks so much for reporting this @George_GL.

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [February 12, 2025, 4:54pm UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/14 "2025-02-12T16:54:17Z")

</div>

> [@andre.pfeuffer](#):
>
> Speed up is significant as shown here:

I’ll add the link to the blog post collecting the information about the different options for improved speed [Options for improving Stan sampling speed – The Stan Blog](https://blog.mc-stan.org/2022/08/03/options-for-improving-stan-sampling-speed/)

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [February 12, 2025, 7:34pm UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/15 "2025-02-12T19:34:39Z")

</div>

> [@avehtari](#):
>
> I’ll add the link to the blog post collecting the information about the different options for improved speed [Options for improving Stan sampling speed – The Stan Blog](https://blog.mc-stan.org/2022/08/03/options-for-improving-stan-sampling-speed/)

@avehtari what do you think about linking to your blog post from the CmdStanR documentation?

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [February 12, 2025, 8:03pm UTC](https://discourse.mc-stan.org/t/best-cpu-for-rstan-brms/30808/16 "2025-02-12T20:03:23Z")

</div>

> [@jonah](#):
>
> @avehtari what do you think about linking to your blog post from the CmdStanR documentation?

Sure. It’s on [mc-stan.org](http://mc-stan.org), so it should be stable. Would be good to check that ally advise are still valid
