Hi, In an MCMC algorithm, we noticed that our C++ code runs a lot slower on Windows than on macOs or Linux (the algorithm takes ~20 seconds on Mac, and easily 2.5 minutes on Windows). After profiling, it appeared that the main time difference was in the time spent in calls to std::exp and std::log.
To investigate this further, I used a machine that dual-boots Windows 11 and Linux. In addition to calling the primitive functions `exp` and `log` in R, I also compared the implementation used by OpenLibm (https://github.com/JuliaMath/openlibm): A subset of the timings are as follows. | OS \ Method | Exp | Exp openlibm | Log | Log openlibm | |---------------------------------------------------------------| | Windows | 43.04ms | 12.96ms | 23.42ms | 11.35ms | | Linux | 4.81ms | 9.44ms | 5.76ms | 9.51ms | These are median timings of computing the function for 1E6 elements. Full timings can be found here: https://github.com/vandenman/expTest/blob/main/bench_exp_and_log.R. This repository also contains a mwe for the OpenLibm version (under src/e_exp.cpp). Some observations: 1. on Windows, Base R exp is about 8.9 times slower than on Linux. 2. on Windows, OpenLibm exp is about 3.3 times faster than Base R. 3. on Linux, Base R exp is about 1.9 times faster than OpenLibm. 4. for log the results are similar albeit less extreme. Is this performance difference between Windows and other OSes known? Is there a recommended way to fix or avoid it? Most of our software's users (and I bet R's users as well) use Windows so this has quite an impact. Kind regards, Don [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.