浏览代码

adat perf code

Bastien Sevajol 8 年前
父节点
当前提交
f435594dc8
共有 2 个文件被更改,包括 17 次插入12 次删除
  1. 12 7
      perf.py
  2. 5 5
      sandbox/perf/simulation.py

+ 12 - 7
perf.py 查看文件

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

+ 5 - 5
sandbox/perf/simulation.py 查看文件

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