ソースを参照

adat perf code

Bastien Sevajol 7 年 前
コミット
f435594dc8
共有2 個のファイルを変更した17 個の追加12 個の削除を含む
  1. 12 7
      perf.py
  2. 5 5
      sandbox/perf/simulation.py

+ 12 - 7
perf.py ファイルの表示

@@ -11,7 +11,7 @@ import time
11 11
 from collections import OrderedDict
12 12
 from random import randint
13 13
 
14
-from sandbox.perf.simulation import ComputeSubject
14
+from sandbox.perf.simulation import ComputeSubject, ComputeBehaviour, ComputeMechanism
15 15
 from synergine2.config import Config
16 16
 from synergine2.cycle import CycleManager
17 17
 from synergine2.log import SynergineLogger
@@ -22,13 +22,18 @@ def simulate(complexity, subject_count, cycle_count, cores):
22 22
     config = Config(dict(complexity=complexity, core=dict(use_x_cores=cores)))
23 23
     simulation = Simulation(config)
24 24
 
25
+    simulation.add_to_index(ComputeSubject)
26
+    simulation.add_to_index(ComputeBehaviour)
27
+    simulation.add_to_index(ComputeMechanism)
28
+
25 29
     subjects = Subjects(simulation=simulation)
26 30
     for i in range(subject_count):
27
-        subjects.append(ComputeSubject(
31
+        subject = ComputeSubject(
28 32
             config=config,
29 33
             simulation=simulation,
30
-            data=[randint(0, 1000) for i in range(1000)]
31
-        ))
34
+        )
35
+        subject.data = [randint(0, 1000) for i in range(1000)]
36
+        subjects.append(subject)
32 37
 
33 38
     simulation.subjects = subjects
34 39
 
@@ -54,10 +59,10 @@ def main():
54 59
     args = parser.parse_args()
55 60
 
56 61
     host_cores = multiprocessing.cpu_count()
57
-    retry = 3
62
+    retry = 1
58 63
     cycles = 10
59
-    subject_counts = [100, 500]
60
-    complexities = [100, 2000]
64
+    subject_counts = [500]
65
+    complexities = [200]
61 66
     max_cores = args.max_cores or host_cores
62 67
 
63 68
     results = []

+ 5 - 5
sandbox/perf/simulation.py ファイルの表示

@@ -1,6 +1,7 @@
1 1
 import random
2 2
 
3 3
 from synergine2.config import Config
4
+from synergine2.share import shared
4 5
 from synergine2.simulation import SubjectMechanism, SubjectBehaviour, Event, Subject
5 6
 
6 7
 
@@ -40,11 +41,11 @@ class ComputeBehaviour(SubjectBehaviour):
40 41
     use = [ComputeMechanism]
41 42
 
42 43
     def run(self, data):
43
-        return not data.get(ComputeMechanism).get('mechanism_value') % 2
44
+        return not data.get('ComputeMechanism').get('mechanism_value') % 2
44 45
 
45 46
     def action(self, data):
46
-        mechanism_value = data.get(ComputeMechanism).get('mechanism_value')
47
-        complexity = data.get(ComputeMechanism).get('complexity')
47
+        mechanism_value = data.get('ComputeMechanism').get('mechanism_value')
48
+        complexity = data.get('ComputeMechanism').get('complexity')
48 49
 
49 50
         if not int(str(mechanism_value)[-1]) % 2:
50 51
             compute(complexity)
@@ -54,12 +55,11 @@ class ComputeBehaviour(SubjectBehaviour):
54 55
 
55 56
 class ComputeSubject(Subject):
56 57
     behaviours_classes = [ComputeBehaviour]
58
+    data = shared.create(['{id}', 'data'], [])
57 59
 
58 60
     def __init__(
59 61
         self,
60 62
         config: Config,
61 63
         simulation: 'Simulation',
62
-        data,
63 64
     ):
64 65
         super().__init__(config, simulation)
65
-        self.data = data