csgillespie / benchmarkme

Crowd sourced benchmarking
https://csgillespie.github.io/benchmarkme/
40 stars 13 forks source link

get_ram() is slow on macOS #6

Closed richierocks closed 7 years ago

richierocks commented 7 years ago

system("system_profiler -detailLevel mini", intern = TRUE)) takes ~ 10 seconds to run on my recent Macbook Air.

substring(system("sysctl hw.memsize", intern = TRUE), 13) takes a few microseconds.

Output is a string, units are bytes. "8589934592"

Command found here:

https://stackoverflow.com/questions/583736/determine-physical-mem-size-programmatically-on-osx#comment30400379_818741

csgillespie commented 7 years ago

Thanks. I've updated the package with your suggestion. Would you test as I don't have access to a Shiny Mac.

devtools::install_github("csgillespie/benchmarkme")
benchmarkme::get_ram()

As an aside, do you have a mavericks OS (https://cran.r-project.org/web/checks/check_results_benchmarkme.html) Not sure where get_ram() fails

richierocks commented 7 years ago

Yes, all working. My Mac is running Sierra rather than Mavericks, and system_profiler definitely existed for me. This update should remove that problem though.

richierocks commented 7 years ago

Actually, it isn't quite right. The conversion from GB to bytes thinks that a kB is 1000 bytes, not 1024 bytes. So it is reporting 8.59 GB instead of 8 GB for me.

Looks like the problem is in to_Bytes().

csgillespie commented 7 years ago

One GB is 10^9 bytes, this is the SI specification (https://en.wikipedia.org/wiki/Kilobyte).

Your ram is 8589934592, so 8.58GB or 8 GiB. It's all just a bit of a mess.


As an aside, your comment did uncover another bug for Linux, where 1KB = 1024B!

m-dz commented 7 years ago

Hi Colin, just a comment on the kB/KB mess: in SI system k stands for kilo (10^2), so 1 kB would be actually 1000 bytes, and 1 KB (as Linux is reporting, imo correctly) would be 1012 bytes. First paragraph of https://en.wikipedia.org/wiki/Kilobyte addresses this topic.

csgillespie commented 7 years ago

Thanks for comment. I think I've got it correct now. As I understand it Linux goes from 1024 bytes = 1KB then switches to 1 MB = 10^6B.

My comment above "bug for Linux" was meant I had a bug, not Linux.

Thanks again

m-dz commented 7 years ago

This "Linux goes from 1024 bytes = 1KB then switches to 1 MB = 10^6B" is asking for trouble... But not much can be done there. Thanks for the great package!