There was a time when people pretty much ignored the distinction between MB and 
MiB in computer applications, and using the binary version was usually assumed 
because, well, this _is_ memory we are measuring. I think this is a leftover 
from that time.

On July 1, 2024 6:33:43 AM PDT, "Sauer, Lukas Daniel" 
<sa...@imbi.uni-heidelberg.de> wrote:
>Hello,
>
>I am profiling memory usage using utils::Rprof() and subsequently summarizing 
>the profile using utils::summaryRprof(). According to the documentation 
>?summaryRprof, the option `memory = "both"` reports "memory consumption in Mb 
>in addition to the timings", i.e. the unit is megabytes. However, looking at 
>the source code 
>(https://github.com/wch/r-source/blob/18652de8890d89563b923ff58b45ccb04d9955fe/src/library/utils/R/summRprof.R#L170)
> suggests that memory is reported in mebibytes (division by 1048576 and not by 
>100000). This is in line with the following minimal example:
>
>use_mb <- function(){a <- runif(1000000)}
>use_mib <- function(){b <- runif(1024^2)}
>Rprof("Rprof.out", memory.profiling=TRUE)
>use_mb()
>use_mib()
>Rprof(NULL)
>summaryRprof("Rprof.out", memory="both")
>
>Do not source this code, but execute it line by line. This example returns the 
>output:
>
>$by.self
>        self.time self.pct total.time total.pct mem.total
>"runif"      0.04      100       0.04       100      15.6
>
>$by.total
>          total.time total.pct mem.total self.time self.pct
>"runif"         0.04       100      15.6      0.04      100
>"use_mb"        0.02        50       7.6      0.00        0
>"use_mib"       0.02        50       8.0      0.00        0
>
>$sample.interval
>[1] 0.02
>
>$sampling.time
>[1] 0.04
>
>The example was run under:
>
>R version 4.4.0 (2024-04-24 ucrt)
>Platform: x86_64-w64-mingw32/x64
>Running under: Windows 11 x64 (build 22631)
>
>If the unit were megabytes, I would expect mem.total to be 16.4, 8.0, and 8.4 
>-- but rather it is 15.6, 7.6, and 8.0. Do you agree that this behavior is 
>unexpected or did I overlook something? If yes, I will file a bug report and 
>suggest that the documentation is changed to "memory consumption in MiB in 
>addition to the timings".
>
>Best regards,
>
>Lukas D Sauer
>Biometrician
>Institute of Medical Biometry
>
>Heidelberg University Hospital | Im Neuenheimer Feld 130.3 | D-69120 Heidelberg
>Tel. +49 6221 56-35036 | Fax. +49 6221 56-4195 | E-Mail: 
>sa...@imbi.uni-heidelberg.de
>biometrie.uni-heidelberg.de | twitter.com/imbi_heidelberg
>
>______________________________________________
>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 http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

______________________________________________
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 http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to