Skip to content

Commit

Permalink
code: added app for testing query performance
Browse files Browse the repository at this point in the history
  • Loading branch information
inlife committed Sep 18, 2022
1 parent fa90cc9 commit b76ba24
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions code/apps/query-performance.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#define LIBRG_IMPL
// #define LIBRG_ENTITY_MAXCHUNKS 1
#include "librg.h"

#define MAX_ENTITY 1000000
#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
//

librg_world_destroy(world);
return 0;
}

0 comments on commit b76ba24

Please sign in to comment.