History

add script to measure cost of entity lookup by id

Andrew Meadows committed 9 years ago

Commit de213911 parent c7ec82f1 file · +104 −0Browse files

Showing the changes to scripts/developer (1 of 1 file). Show all

Unified · Split

scripts/developer/tests/entityLookupCostMeasurement.js+104−0
@@ -0,0 +1,104 @@
1+// Creates a large number of entities on the cardinal planes of the octree (all
2+// objects will live in the root octree element). Measures how long it takes
3+// to update the properties of the first and last entity. The difference
4+// between the two measurements shows how the cost of lookup changes as a
5+// function of the number of entities. For best results run this in an
6+// otherwise empty domain.
7+
8+var firstId;
9+var lastId;
10+var NUM_ENTITIES_ON_SIDE = 25;
11+
12+// create the objects
13+createObjects = function () {
14+ var STRIDE = 0.75;
15+ var WIDTH = 0.5;
16+ var DIMENSIONS = { x: WIDTH, y: WIDTH, z: WIDTH };
17+ var LIFETIME = 20;
18+
19+ var properties = {
20+ name: "",
21+ type : "Box",
22+ dimensions : DIMENSIONS,
23+ position : { x: 0, y: 0, z: 0},
24+ lifetime : LIFETIME,
25+ color : { red:255, green: 64, blue: 255 }
26+ };
27+
28+ // xy
29+ var planeName = "xy";
30+ for (var i = 0; i < NUM_ENTITIES_ON_SIDE; ++i) {
31+ for (var j = 0; j < NUM_ENTITIES_ON_SIDE; ++j) {
32+ properties.name = "Box-" + planeName + "-" + i + "." + j;
33+ properties.position = { x: i * STRIDE, y: j * STRIDE, z: 0 };
34+ var red = i * 255 / NUM_ENTITIES_ON_SIDE;
35+ var green = j * 255 / NUM_ENTITIES_ON_SIDE;
36+ var blue = 0;
37+ properties.color = { red: red, green: green, blue: blue };
38+ if (i == 0 && j == 0) {
39+ firstId = Entities.addEntity(properties);
40+ } else {
41+ Entities.addEntity(properties);
42+ }
43+ }
44+ }
45+
46+ // yz
47+ var planeName = "yz";
48+ for (var i = 0; i < NUM_ENTITIES_ON_SIDE; ++i) {
49+ for (var j = 0; j < NUM_ENTITIES_ON_SIDE; ++j) {
50+ properties.name = "Box-" + planeName + "-" + i + "." + j;
51+ properties.position = { x: 0, y: i * STRIDE, z: j * STRIDE };
52+ var red = 0;
53+ var green = i * 255 / NUM_ENTITIES_ON_SIDE;
54+ var blue = j * 255 / NUM_ENTITIES_ON_SIDE;
55+ properties.color = { red: red, green: green, blue: blue };
56+ Entities.addEntity(properties);
57+ }
58+ }
59+
60+ // zx
61+ var planeName = "zx";
62+ for (var i = 0; i < NUM_ENTITIES_ON_SIDE; ++i) {
63+ for (var j = 0; j < NUM_ENTITIES_ON_SIDE; ++j) {
64+ properties.name = "Box-" + planeName + "-" + i + "." + j;
65+ properties.position = { x: j * STRIDE, y: 0, z: i * STRIDE };
66+ var red = j * 255 / NUM_ENTITIES_ON_SIDE;
67+ var green = 0;
68+ var blue = i * 255 / NUM_ENTITIES_ON_SIDE;
69+ properties.color = { red: red, green: green, blue: blue };
70+ lastId = Entities.addEntity(properties);
71+ }
72+ }
73+};
74+
75+createObjects();
76+
77+// measure the time it takes to edit the first and last entities many times
78+// (requires a lookup by entityId each time)
79+changeProperties = function (id) {
80+ var newProperties = { color : { red: 255, green: 255, blue: 255 } };
81+ Entities.editEntity(id, newProperties);
82+}
83+
84+// first
85+var NUM_CHANGES = 10000;
86+var firstStart = Date.now();
87+for (var k = 0; k < NUM_CHANGES; ++k) {
88+ changeProperties(firstId);
89+}
90+var firstEnd = Date.now();
91+var firstDt = firstEnd - firstStart;
92+
93+// last
94+var lastStart = Date.now();
95+for (var k = 0; k < NUM_CHANGES; ++k) {
96+ changeProperties(lastId);
97+}
98+var lastEnd = Date.now();
99+var lastDt = lastEnd - lastStart;
100+
101+// print the results
102+var numEntities = 3 * NUM_ENTITIES_ON_SIDE * NUM_ENTITIES_ON_SIDE;
103+print("numEntities = " + numEntities + " numEdits = " + NUM_CHANGES + " firstDt = " + firstDt + " lastDt = " + lastDt);
104+

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t