[erlang-questions] Measuring GC pressure and memory efficiency

Joel Reymont joelr1@REDACTED
Fri Dec 14 12:37:50 CET 2007


I would like to measure the memory efficiency of the following module.  
I suppose this would tell me how much pressure it puts on the GC,  
except it may not because it uses binaries.

How do I measure the amount of temporary binaries each function  
generates as well as the total amount of garbage?

	Thanks, Joel

P.S. This is code written by Julian Fondren for this thread:

http://erlang.org/pipermail/erlang-questions/2006-December/024591.html

---

-module(arrays).

-export([new/1, new/2, new/3, get/2, put/3, size/1, elt_width/1]).

new(Size) ->
     new(Size,0,32).

new(Size,Init) ->
     new(Size,Init,32).

new(Size,Init,Width) when Size > 0, Width > 8, Width rem 8 == 0 ->
     new(Size,Init,Width,<<>>).

new(0,_,W,B) ->
     <<W:32, B/binary>>;

new(N,I,W,B) ->
     new(N-1,I,W,<<I:W, B/binary>>).

get(N,<<W:32,B/binary>>) when N > 0 ->
     Before = W * (N - 1),
     <<_:Before, X:W,
      _/binary>> = B, X.

put(N,X,<<W:32,B/binary>>) when N > 0 ->
     Before = W * (N - 1),
     <<Bef:Before, _:W, After/binary>> = B,
     <<W:32, Bef:Before, X:W, After/binary>>.

size(<<W:32, B/binary>>) ->
     erlang:size(B) div (W div 8).

elt_width(<<W:32, _/binary>>) ->
     W.

--
http://wagerlabs.com








More information about the erlang-questions mailing list