memuse v4.0-0

0

Monthly downloads

0th

Percentile

Memory Estimation Utilities

How much ram do you need to store a 100,000 by 100,000 matrix? How much ram is your current R session using? How much ram do you even have? Learn the scintillating answer to these and many more such questions with the 'memuse' package.

Readme

memuse

memuse is an R package for memory estimation. It has tools for estimating the size of a matrix (that doesn't exist), showing the size of an existing object in a nicer way than object.size(). It also has tools for showing how much memory the current R process is consuming, how much ram is available on the system, and more.

Originally, this package was an over-engineered solution to a mostly non-existent problem, as a sort of love letter to other needlessly complex programs like the Enterprise Fizzbuzz. However, as of version 2.0-0, I'm sad to report that the package is actually becoming quite useful.

The package has been exhaustively tested on Linux, FreeBSD, Windows, Mac, and "other"-NIX. That is also roughly the platforms in descending order of support for the various operations. However, if you have a problem installing or using the package, please open an issue on the project's GitHub repository.

Installation

To install the R package, run:

install.package("memuse")

The development version is maintained on GitHub, and can easily be installed by any of the packages that offer installations from GitHub:

### Pick your preference
devtools::install_github("shinra-dev/memuse")
ghit::install_github("shinra-dev/memuse")
remotes::install_github("shinra-dev/memuse")

The C internals, found in memuse/src/meminfo/ are completely separated from the R wrapper code. So if you prefer, you can easily build this as a standalone C shared library.

Package Utilities

The package comes with several classes of utilities. I find all of them very useful during the course of benchmarking, but some are certainly more useful than others.

Memory Lookups

With this package you can get some information about how much memory is physically available on the host machine:

Sys.meminfo()
# Totalram:  15.656 GiB 
# Freeram:   10.504 GiB 

Sys.meminfo(compact.free=FALSE) ### Linux and FreeBSD only
# Totalram:   15.656 GiB 
# Freeram:     1.067 GiB 
# Bufferram:   1.332 GiB 
# Cachedram:   8.207 GiB 

Sys.swapinfo() ## same as Sys.pageinfo()
# Totalswap:    32.596 GiB 
# Freeswap:     32.595 GiB 
# Cachedswap:  444.000 KiB

You can find the ram usage of the current R process:

Sys.procmem()
# Size:  258.426 MiB 
# Peak:  258.426 MiB 

x <- rnorm(1e8)
memuse(x)
# 762.939 MiB

rm(x);invisible(gc())

Sys.procmem()
# Size:   258.426 MiB 
# Peak:  1021.363 MiB

Also, if you're working close to the metal, you may be interested in seeing how large the CPU caches are and/or how big the cache linesize is:

Sys.cachesize()
# L1I:   32.000 KiB 
# L1D:   32.000 KiB 
# L2:   256.000 KiB 
# L3:     6.000 MiB 

Sys.cachelinesize()
# Linesize:  64 B

Estimating Memory Usage

You can estimate memory storage requirements of a matrix without having to divide by some annoying power of 2:

howbig(10000, 500)
# 38.147 MiB

howbig(10000, 500, type="int")
# 19.073 MiB

howbig(10000, 500, representation="sparse", sparsity=.05)
# 1.907 MiB

Alternatively, given a (memory) size, you can also find the dimensions of such a matrix:

howmany(mu(800, "mib"))
# [1] 10240 10240
howmany(mu(800, "mib"), ncol=500)
# [1] 209715    500

For more information, see the package vignette.

Misc

The package also has some miscellaneous helpful utilities:

approx.size(12345)
# 12.3 Thousand

approx.size(123456789)
# 123.5 Million

approx.size(123456789, unit.names="short")
# 123.5m

approx.size(123456789, unit.names="comma")
# 123,456,789

Authors

memuse is authored and maintained by:

  • Drew Schmidt

With additional contributions from:

  • Christian Heckendorf (FreeBSD improvements to meminfo)
  • Wei-Chen Chen (Windows build fixes)
  • Dan Burgess (donation of a Mac for development and testing)

Functions in memuse

Name Description
howmany howmany
sum,memuse-method memuse Arithmetic
swapinfo swapinfo
Converters Converters
filesize filesize
memuse-class Class memuse
memuse-package Core memuse Classes and Methods
cachelinesize Cache Sizes and Linesize
cachesize Cache Sizes
print-hr Print humanreadable objects
print-memuse Printing
Comparators Comparators
Constructor memuse Constructor
print-sysinfo Print sysinfo objects
procmem procmem
hr hr
meminfo meminfo
Accessors Accessors
Arithmetic Binary Arithmetic
Swaps Swaps
howbig howbig
No Results!

Vignettes of memuse

Name
cover/cover.pdf
include/00-acknowledgement.tex
include/00-copyright.tex
include/01-introduction.tex
include/02-installation.tex
include/03-sizematters.tex
include/04-memuse.tex
include/05-other.tex
include/06-meminfo.tex
include/lastpage.sty
include/preamble.tex
include/titlepage.tex
build_pdf.sh
memuse-guide.Rnw
No Results!

Last month downloads

Details

License BSD 2-clause License + file LICENSE
NeedsCompilation yes
ByteCompile yes
URL https://github.com/shinra-dev/memuse
BugReports https://github.com/shinra-dev/memuse/issues
RoxygenNote 6.0.1
Packaged 2017-11-10 13:08:29 UTC; mschmid3
Repository CRAN
Date/Publication 2017-11-10 19:04:08 UTC

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/memuse)](http://www.rdocumentation.org/packages/memuse)