From 3e3af78ccde6eba101ef385a6b8e444be66e8f3d Mon Sep 17 00:00:00 2001 From: Richard Feistenauer Date: Sun, 10 Feb 2019 11:00:57 +0100 Subject: [PATCH] refactoring --- performance.txt | 13 +++++++++++++ scripts/main_ui.py | 19 ++++++------------- scripts/performance_test | Bin 3861 -> 3861 bytes src/cellular_automaton/ca_cell_state.py | 2 +- src/cellular_automaton/ca_display.py | 3 +-- 5 files changed, 21 insertions(+), 16 deletions(-) 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 6b88c5966074883b6715e97601db6b7bcdfcfdcf..7ab56b929eddf51980b0589ee55d64115ede0b85 100644 GIT binary patch literal 3861 zcmbtXYitx%6fQ1(^Qb6jh0+BrwLI2_5;T;|RKREi42F=PS)EL0Z*K=?XO=s&eWXzg zF(M6GLWqXi#Ar0i4@DF(kz(Sj5+VsfgSr%fgh!V~1R)@c0ngppxifcWOGx~4dw1r$ z-*?Wr=bSmcQ5VWAU%Vi?%0$GBHfu>FX-Qp5BkOl}ZxQEkvk_=hSg)%`2rp{4U^SJ=-D& z>dy*HWzt=6YIM7-TAWPa0F${)WxyBIVfzwLNeg)9>C1iP>;DqENQvKmo7jV4#MdeD zScxDF$tIFaxeev_;Z}9|gn_n`t`8+NQlVhk6_Tv1OR5BcqG=g~7wc>w zA3gc)X#xK@;p$gsoBjq@#`y&T7$$Iw3Y1E!DH-iLig9lA6rNIw%YPAYczExgr`|o6 zk2!#Gm{r$R@AZ~#T6D2ya)pRD9ezgnLfI$g348#3p{S7+~h zv+Vt!1ng|Opg``03sKk8R4=4u*~#U)17s(d2rUjfvAmJ#y;-&N;Q4Y9zp-V0;~%XM zZAW1v!*eC;#{+*x%M-~ZhLVg!`9f2%yGuM9p=^VZ+6|(`B#d-KWJuSjNtCF9G%cyg zM3R%15r@Zmo=3C+O`!=n4z(Ft8KRrFpvA-MesSt+B^704pjNi?BFaMRjKR2`- zft)&UXuCYD!ZncT{+I+XjFZ|x9`xIMb7#fmy3hX+@Vv;|TYELiInB=*z%WiXZeBZA zH)blgFKQ6+#HD4o8W%UY_eigwg#G*hJmsGZD7z|XtwEgK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qAohrqXx|%&Hhxbcd4>CNP;|If`WKZJ$%?u&rBecm zwqsFV%w54DN%L6JbYW0Hz%YU9C{QcwwrmZXB+f0vbDs~=Bm_xd7BC*OURbJsdp90< zHS&4qZ<2N?e7vgc=tQ(g-~|lhEF_wr^O7_8Ti zUuY_BcS+R%ewMVkCmLSsyO>+kR86<-P_Q87Y8*Z$ta!>G5*IyTCPwcr z(948Tw8|Cb#J2BR*;043Gpbd^FC6>&f*U}bLhr`MJ@DWp1UyRQwzL|vpgf@@Ieyk- z_B}drxamtDKgNMJ1^ER$;~z%;IvE6H#U3?PPNr?^AFmwl`5P)E-d?w3&m&kN1zU7U zP)5KPWLWb1^X$8H$Lo*%IxT7D7i-U4X{s#b+1m{7&ocqf_%ZWoBl_|4yXk&{Z>YJj z?g#u-xdxTx=NIsdzmWHSey??EH6ISX@H^HCT^5XqfMJ~Ifi4evb{oPONo!R1>pjPi zGaTd;FpRShH^0x>uO52p-I=bawyyc<-hr3a6!sCfpDqpZ3wY$e7f|j|cpu{Z{BAct zD`|;0+cv-B)>gJ`R|asQ?9%SOlx{d3x*1LoxJksrxzD<3N5}|K`C1d0Q27B=UV&Vl z-Fb=@C7C2FtZ^OqTcyO8S#(CVUjB&|>-;VHxAl!|L?*Pf4=ov`i5N(5p z)-%~X_7OVp2Bnskzy8d>G~b;|*b%n0TTy&Laj(8z=8Z&HjM+uX#GbWrNhNqx|XfajgG2sJ9_b51cJ>l6omAwcqBIpJozJ08Az;`oL) zu1K0UnD3tFhT^nDD}&bD%fn?!^9H=NWr8)P*{ za0+?@CN~d;mz$@Dn`Fef;qvYXZov(fS18hC%E=c6^z{^pY|#@*gFK02cwel`AE=yG YtLx86nm1s}&9%$iZ&L3ohUx755B2m|Pyhe` 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()