end
),
- {NewTime, NewBoard} = timer:tc(fun() -> next_generation(X, Y, Board) end),
+ {NewTime, NewBoard} = timer:tc(
+ fun() ->
+ next_generation(X, Y, Board)
+ end
+ ),
+
NewState = State#state{board = NewBoard
,gen_count = GenCount + 1
,gen_duration = NewTime
do_print_board(Board) ->
- CharLists = array:to_list(
+ % It seems that just doing a fold should be faster than map + to_list
+ % combo, but, after measuring several times, map + to_list has been
+ % consistently (nearly twice) faster than either foldl or foldr.
+ RowStrings = array:to_list(
array:map(
fun(_, Row) ->
array:to_list(
),
ok = lists:foreach(
- fun(CharList) ->
- ok = io:format("~s~n", [CharList])
+ fun(RowString) ->
+ ok = io:format("~s~n", [RowString])
end,
- CharLists
+ RowStrings
).