-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathquery-performance.c
63 lines (49 loc) · 1.91 KB
/
query-performance.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#define LIBRG_IMPL
// #define LIBRG_ENTITY_MAXCHUNKS 1
#include "librg.h"
#define MAX_ENTITY 1000
#define QUERY_ATTEMPTS 1000
int main() {
librg_world *world = librg_world_create();
/* create our world configuration */
librg_config_chunksize_set(world, 16, 16, 0);
librg_config_chunkamount_set(world, 64, 64, 0);
librg_config_chunkoffset_set(world, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG);
zpl_f64 tstart = zpl_time_rel_ms();
/* create set of testing entities */
for (int i = 0; i < MAX_ENTITY; ++i) {
int chx = rand() % 64;
int chy = rand() % 64;
librg_entity_track(world, i);
librg_chunk chid = librg_chunk_from_chunkpos(world, chx, chy, 0);
librg_entity_chunk_set(world, i, chid);
}
zpl_printf("[test] tracked %d entities in (%.3f ms)\n", librg_world_entities_tracked(world), zpl_time_rel_ms() - tstart);
/* set owner to a single entity */
int ownerid = 1;
librg_entity_owner_set(world, 0, ownerid);
/* fetch entities via query */
int64_t entities[1000] = {0};
size_t entity_amount = 1000;
int query_radius = 16;
tstart = zpl_time_rel();
for (int i = 0; i < QUERY_ATTEMPTS; ++i) {
size_t entity_limit = 1000;
librg_world_query(world, ownerid, query_radius, entities, &entity_limit);
entity_amount = entity_limit;
}
zpl_printf("[test] found %d entities in (%.3f ms)\n", entity_amount, zpl_time_rel_ms() - tstart);
/* results */
//
// before switch to internal memory
// [test] found 171 entities in (7800.685 ms)
// [test] found 171 entities in (7789.673 ms)
// [test] found 171 entities in (7804.661 ms)
//
// after switch to internal memory
// [test] found 171 entities in (4308.592 ms)
// [test] found 171 entities in (4234.625 ms)
// [test] found 171 entities in (4221.636 ms)
librg_world_destroy(world);
return 0;
}