Changeset 1116 for framspy


Ignore:
Timestamp:
03/27/21 03:42:04 (4 years ago)
Author:
Maciej Komosinski
Message:

Improved performance significantly by moving the step-by-step simulation loop from python to FramScript?

Location:
framspy
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • framspy/FramsticksLib.py

    r1114 r1116  
    8181                frams.Simulator.init()
    8282                frams.Simulator.start()
    83                 step = frams.Simulator.step  # cache reference to avoid repeated lookup in the loop (just for performance)
    84                 while frams.Simulator.running._int():  # standard-eval.expdef sets running to 0 when the evaluation is complete
    85                         step()
     83
     84                # step = frams.Simulator.step  # cache reference to avoid repeated lookup in the loop (just for performance)
     85                # while frams.Simulator.running._int():  # standard-eval.expdef sets running to 0 when the evaluation is complete
     86                #       step()
     87                frams.Simulator.eval("while(Simulator.running) Simulator.step();")  # fastest
     88                # Timing for evaluating a single simple creature 100x:
     89                # - python step without caching: 2.2s
     90                # - python step with caching   : 1.6s
     91                # - pure FramScript and eval() : 0.4s
    8692
    8793                if not self.PRINT_FRAMSTICKS_OUTPUT:
  • framspy/frams-test.py

    r1114 r1116  
    9393frams.Simulator.init()
    9494frams.Simulator.start()
    95 step = frams.Simulator.step  # cache reference to avoid repeated lookup in the loop (just for performance)
    96 while frams.Simulator.running._int():  # standard-eval.expdef sets running to 0 when the evaluation is complete
    97         step()
     95# step = frams.Simulator.step  # cache reference to avoid repeated lookup in the loop (just for performance)
     96# while frams.Simulator.running._int():  # standard-eval.expdef sets running to 0 when the evaluation is complete
     97#       step()
     98frams.Simulator.eval("while(Simulator.running) Simulator.step();")  # loop in FramScript much faster than loop in python
    9899for g in frams.GenePools[0]:  # loop over all genotypes, even though we know we added only one
    99100        serialized_dict = frams.String.serialize(g.data[frams.ExpProperties.evalsavedata._value()])
Note: See TracChangeset for help on using the changeset viewer.