diff --git a/performance.txt b/performance.txt index 7726429..277cf6d 100644 --- a/performance.txt +++ b/performance.txt @@ -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 diff --git a/scripts/main_ui.py b/scripts/main_ui.py index 8b7f345..baad7a5 100644 --- a/scripts/main_ui.py +++ b/scripts/main_ui.py @@ -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) diff --git a/scripts/performance_test b/scripts/performance_test index 6b88c59..7ab56b9 100644 Binary files a/scripts/performance_test and b/scripts/performance_test differ diff --git a/src/cellular_automaton/ca_cell_state.py b/src/cellular_automaton/ca_cell_state.py index cc48640..4aa0020 100644 --- a/src/cellular_automaton/ca_cell_state.py +++ b/src/cellular_automaton/ca_cell_state.py @@ -42,7 +42,7 @@ class CellState: def set_state_of_iteration(self, new_state, iteration): """ Will set the new state for the iteration modulo number of saved states. :param new_state: The new state to set. - :param iteration: Uses the iteration index, to differ between concurrent states. + :param iteration: Uses the iteration index, to differ between concurrent states. :return True if state has changed. """ diff --git a/src/cellular_automaton/ca_display.py b/src/cellular_automaton/ca_display.py index f642002..9fee63e 100644 --- a/src/cellular_automaton/ca_display.py +++ b/src/cellular_automaton/ca_display.py @@ -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()