home
/
code
/
cellular-automata.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Don't sleep longer than necessary to meet the interval.
[cellular-automata.git]
/
003
/
src
/
life.erl
diff --git
a/003/src/life.erl
b/003/src/life.erl
index
5f91d26
..
f4b1fe5
100644
(file)
--- a/
003/src/life.erl
+++ b/
003/src/life.erl
@@
-7,7
+7,7
@@
-define(CHAR_ALIVE, 111). % "o"
-define(CHAR_BAR, 45). % "-"
-define(CHAR_ALIVE, 111). % "o"
-define(CHAR_BAR, 45). % "-"
--define(INTERVAL, 100).
+-define(
GEN_
INTERVAL, 100).
-record(state, {x :: non_neg_integer()
-record(state, {x :: non_neg_integer()
@@
-73,7
+73,10
@@
life_loop(
,print_time = PrintTime
},
,print_time = PrintTime
},
- timer:sleep(?INTERVAL),
+ NewTimeMil = NewTime / 1000,
+ NextGenDelay = round(?GEN_INTERVAL - NewTimeMil),
+ timer:sleep(NextGenDelay),
+
life_loop(NewState).
life_loop(NewState).
@@
-94,6
+97,9
@@
do_print_status(Bar, X, Y, N, GenCount, TimeMic, PrintTimeMic) ->
do_print_board(Board) ->
do_print_board(Board) ->
+ % 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) ->
RowStrings = array:to_list(
array:map(
fun(_, Row) ->
This page took
0.02169 seconds
and
4
git commands to generate.