[erlang-questions] Performance Testing with C++, Java, Ruby and Erlang

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Mon Sep 10 09:30:23 CEST 2007


Ulf Wiger (TN/EAB) wrote:
> 
> The set_node_value/1 function is called from within a lists:foreach(),
> when you should rather use e.g. lists:foldl() with Nodes as an
> accumulator. That would eliminate all the get() and put() operations,
> as the updated Nodes variable is passed on to the next iteration.
> 
> set_node_value(Round, #config{proc_ids = Proc_ids, nodes = Nodes}) ->
>     lists:foldl(
>         fun(Id, Ns) ->
>             set_node_value(Round, Id, Nodes)
>         end, Nodes, ProcIds).

This is of course wrong, and a compiler warning would
have indicated the problem, had I bothered to actually
compile the proposed changes. The call to set_node_value/3
must be done using Ns rather than Nodes:

set_node_value(Round, #config{proc_ids = Proc_ids, nodes = Nodes}) ->
     lists:foldl(
         fun(Id, Ns) ->
             set_node_value(Round, Id, Ns)
         end, Nodes, ProcIds).

BR,
Ulf W



More information about the erlang-questions mailing list