Skip to content

Speed vs Memory

Daniel Berger edited this page Feb 20, 2018 · 3 revisions

The Sys::ProcTable.ps method provides two different ways to read processes - with a block, or without a block.

With a block

This approach reads one record at a time and yields it to the block. It is slower, but memory efficient.

Sys::ProcTable.ps{ |process| ... }

Without a block

This approach reads everything into memory and then hands it to you as an array. It is faster, but can potentially consume quite a bit of memory.

Sys::ProcTable.ps.each{ |process| ... }

Other Options

Starting with version 1.2, you can disable certain information from being collected using keyword arguments. For example, smaps information on Linux can consume a fair amount of memory, so you may want to disable that if you don't care about smaps information.

Sys::ProcTable.ps(smaps: false)

Clone this wiki locally