refactoring
This commit is contained in:
parent
b0a8fb05a4
commit
3e3af78ccd
@ -1,3 +1,16 @@
|
||||
# ~Goal
|
||||
def time_test(s, l):
|
||||
first = time.time()
|
||||
for i in range(100000):
|
||||
s = l[i % 2]
|
||||
last = time.time()
|
||||
print((last-first)/100000)
|
||||
|
||||
time_test(1, [2, 1])
|
||||
1.401543617248535e-07
|
||||
|
||||
heist auf einem processor ohne synchronized müsste ich ca 10 mal schneller sein? oder 3.3 mal weil 3 prozesse weniger?
|
||||
|
||||
# With 100x100 10 times
|
||||
|
||||
Try One
|
||||
|
@ -1,10 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from cellular_automaton.ca_cell_state import CellState
|
||||
from cellular_automaton.ca_rule import Rule
|
||||
|
||||
from cellular_automaton.cellular_automaton import CellularAutomaton, CellularAutomatonProcessor
|
||||
from cellular_automaton.ca_factory import CAFactory
|
||||
import random
|
||||
from multiprocessing import freeze_support
|
||||
from cellular_automaton import *
|
||||
|
||||
|
||||
class TestRule(Rule):
|
||||
@ -40,18 +38,13 @@ def make_cellular_automaton(dimension, neighborhood, rule, state_class):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import random
|
||||
from multiprocessing import freeze_support
|
||||
from cellular_automaton.ca_neighborhood import MooreNeighborhood, EdgeRule
|
||||
from cellular_automaton.ca_display import PyGameFor2D
|
||||
|
||||
freeze_support()
|
||||
|
||||
random.seed(1000)
|
||||
# best single is 400/400 with 0,2 ca speed and 0,09 redraw / multi is 300/300 with 0.083
|
||||
neighborhood = MooreNeighborhood(EdgeRule.FIRST_AND_LAST_CELL_OF_DIMENSION_ARE_NEIGHBORS)
|
||||
ca = make_cellular_automaton(dimension=[100, 100], neighborhood=neighborhood, rule=TestRule(), state_class=MyState)
|
||||
ca_window = PyGameFor2D(window_size=[1000, 800], cellular_automaton=ca)
|
||||
ca_processor = CellularAutomatonProcessor(process_count=4, cellular_automaton=ca)
|
||||
ca_window.main_loop(cellular_automaton_processor=ca_processor,
|
||||
ca_iterations_per_draw=5)
|
||||
|
||||
ca_window = PyGameFor2D(window_size=[1000, 800], cellular_automaton=ca)
|
||||
ca_window.main_loop(cellular_automaton_processor=ca_processor, ca_iterations_per_draw=10)
|
||||
|
Binary file not shown.
@ -38,7 +38,6 @@ class PyGameFor2D:
|
||||
def __init__(self, window_size: list, cellular_automaton: CellularAutomaton):
|
||||
self._window_size = window_size
|
||||
self._cellular_automaton = cellular_automaton
|
||||
self._cellular_automaton_proocessor = None
|
||||
pygame.init()
|
||||
pygame.display.set_caption("Cellular Automaton")
|
||||
self._screen = pygame.display.set_mode(self._window_size)
|
||||
@ -68,7 +67,7 @@ class PyGameFor2D:
|
||||
self._evolve_with_performance(cellular_automaton_processor)
|
||||
first = False
|
||||
else:
|
||||
cellular_automaton_processor.evolve()
|
||||
cellular_automaton_processor.evolve_x_times(ca_iterations_per_draw)
|
||||
time_ca_end = time.time()
|
||||
self.ca_display.redraw_cellular_automaton()
|
||||
time_ds_end = time.time()
|
||||
|
Loading…
Reference in New Issue
Block a user