mirror of
https://github.com/CovidBraceletPrj/CovidBracelet.git
synced 2024-12-05 00:55:43 +01:00
Contacts: Add first draft of test functions
This commit is contained in:
parent
7575ab853f
commit
76ce19d94a
120
src/contacts.c
120
src/contacts.c
@ -54,7 +54,47 @@ int register_record(record_t* record) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_number_of_infected_for_multiple_intervals(infected_for_period_key_ctx_t* ctx, int count) {
|
int get_number_of_infected_for_multiple_intervals_dumb(infected_for_period_key_ctx_t* ctx, int count) {
|
||||||
|
record_iterator_t iterator;
|
||||||
|
int rc = ens_records_iterator_init_timerange(&iterator, NULL, NULL);
|
||||||
|
if (rc) {
|
||||||
|
// there was a general error, so just do nothing
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
while (!iterator.finished) {
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
if (memcmp(&iterator.current.rolling_proximity_identifier, &ctx[i].interval_identifier,
|
||||||
|
sizeof(rolling_proximity_identifier_t)) == 0) {
|
||||||
|
ctx[i].infected++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ens_records_iterator_next(&iterator);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_number_of_infected_for_multiple_intervals_simple(infected_for_period_key_ctx_t* ctx, int count) {
|
||||||
|
printk("start of simple\n");
|
||||||
|
record_iterator_t iterator;
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
int rc = ens_records_iterator_init_timerange(&iterator, &ctx[i].search_start, &ctx[i].search_end);
|
||||||
|
if (rc) {
|
||||||
|
// on error, skip this rpi
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
while (!iterator.finished) {
|
||||||
|
if (memcmp(&iterator.current.rolling_proximity_identifier, &ctx[i].interval_identifier,
|
||||||
|
sizeof(rolling_proximity_identifier_t)) == 0) {
|
||||||
|
ctx[i].infected++;
|
||||||
|
}
|
||||||
|
ens_records_iterator_next(&iterator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_number_of_infected_for_multiple_intervals_optimized(infected_for_period_key_ctx_t* ctx, int count) {
|
||||||
|
printk("start of opt\n");
|
||||||
record_iterator_t iterator;
|
record_iterator_t iterator;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < count) {
|
while (i < count) {
|
||||||
@ -84,6 +124,29 @@ int get_number_of_infected_for_multiple_intervals(infected_for_period_key_ctx_t*
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void measure_perf(test_func_t func, const char* label, infected_for_period_key_ctx_t* infectedIntervals, int count) {
|
||||||
|
printk("---------------------------\n'%s': starting measurement\n", label);
|
||||||
|
|
||||||
|
timing_t start_time, end_time;
|
||||||
|
uint64_t total_cycles;
|
||||||
|
uint64_t total_ns;
|
||||||
|
|
||||||
|
timing_init();
|
||||||
|
timing_start();
|
||||||
|
start_time = timing_counter_get();
|
||||||
|
|
||||||
|
func(infectedIntervals, count);
|
||||||
|
|
||||||
|
end_time = timing_counter_get();
|
||||||
|
|
||||||
|
total_cycles = timing_cycles_get(&start_time, &end_time);
|
||||||
|
total_ns = timing_cycles_to_ns(total_cycles);
|
||||||
|
|
||||||
|
timing_stop();
|
||||||
|
|
||||||
|
printk("\n'%s' took %lld ns\n---------------------------\n", label, total_ns);
|
||||||
|
}
|
||||||
|
|
||||||
void setup_test_data() {
|
void setup_test_data() {
|
||||||
ENPeriodKey infectedPeriodKey = {
|
ENPeriodKey infectedPeriodKey = {
|
||||||
.b = {0x75, 0xc7, 0x34, 0xc6, 0xdd, 0x1a, 0x78, 0x2d, 0xe7, 0xa9, 0x65, 0xda, 0x5e, 0xb9, 0x31, 0x25}};
|
.b = {0x75, 0xc7, 0x34, 0xc6, 0xdd, 0x1a, 0x78, 0x2d, 0xe7, 0xa9, 0x65, 0xda, 0x5e, 0xb9, 0x31, 0x25}};
|
||||||
@ -119,42 +182,29 @@ void setup_test_data() {
|
|||||||
printk("period %d\n", i);
|
printk("period %d\n", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int infectedCount = 36;
|
||||||
|
int spread = 2;
|
||||||
|
|
||||||
// setup our ordered array with infected RPIs
|
// setup our ordered array with infected RPIs
|
||||||
infected_for_period_key_ctx_t infectedIntervals[10];
|
infected_for_period_key_ctx_t infectedIntervals[infectedCount * spread];
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < infectedCount; i++) {
|
||||||
int intervalNumber = (i + 2) * 2;
|
int intervalNumber = (i + 2) * 2;
|
||||||
float offset = 1.5;
|
float range = 1.5;
|
||||||
infectedIntervals[i].infected = 0;
|
for (int j = 0; j < spread; j++) {
|
||||||
infectedIntervals[i].search_start =
|
int offset = (EN_INTERVAL_LENGTH / spread) * j;
|
||||||
(intervalNumber - offset) * EN_INTERVAL_LENGTH; // start one and a half interval before
|
infectedIntervals[i * spread + j].infected = 0;
|
||||||
infectedIntervals[i].search_end =
|
infectedIntervals[i * spread + j].search_start =
|
||||||
(intervalNumber + offset) * EN_INTERVAL_LENGTH; // end one and a half interval after
|
(intervalNumber - range) * EN_INTERVAL_LENGTH + offset; // start one and a half interval before
|
||||||
en_derive_interval_identifier((ENIntervalIdentifier*)&infectedIntervals[i].interval_identifier, &infectedPik,
|
infectedIntervals[i * spread + j].search_end =
|
||||||
intervalNumber);
|
(intervalNumber + range) * EN_INTERVAL_LENGTH + offset; // end one and a half interval after
|
||||||
|
en_derive_interval_identifier(&infectedIntervals[i * spread + j].interval_identifier, &infectedPik,
|
||||||
|
intervalNumber);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printk("starting measurement\n");
|
measure_perf(get_number_of_infected_for_multiple_intervals_dumb, "dumb", infectedIntervals, infectedCount * spread);
|
||||||
|
measure_perf(get_number_of_infected_for_multiple_intervals_simple, "simple", infectedIntervals,
|
||||||
timing_t start_time, end_time;
|
infectedCount * spread);
|
||||||
uint64_t total_cycles;
|
measure_perf(get_number_of_infected_for_multiple_intervals_optimized, "optimized", infectedIntervals,
|
||||||
uint64_t total_ns;
|
infectedCount * spread);
|
||||||
|
|
||||||
timing_init();
|
|
||||||
timing_start();
|
|
||||||
start_time = timing_counter_get();
|
|
||||||
|
|
||||||
get_number_of_infected_for_multiple_intervals(infectedIntervals, 10);
|
|
||||||
|
|
||||||
end_time = timing_counter_get();
|
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
printk("ctx: %d infected: %d\n", i, infectedIntervals[i].infected);
|
|
||||||
}
|
|
||||||
|
|
||||||
total_cycles = timing_cycles_get(&start_time, &end_time);
|
|
||||||
total_ns = timing_cycles_to_ns(total_cycles);
|
|
||||||
|
|
||||||
timing_stop();
|
|
||||||
|
|
||||||
printk("timing took %lld ns\n", total_ns);
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,9 @@ typedef struct infected_for_period_key_ctx {
|
|||||||
int infected;
|
int infected;
|
||||||
time_t search_start;
|
time_t search_start;
|
||||||
time_t search_end;
|
time_t search_end;
|
||||||
} infected_for_period_key_ctx_t;
|
} __packed infected_for_period_key_ctx_t;
|
||||||
|
|
||||||
|
typedef int (*test_func_t)(infected_for_period_key_ctx_t* infectedIntervals, int count);
|
||||||
|
|
||||||
void print_key(_ENBaseKey* key);
|
void print_key(_ENBaseKey* key);
|
||||||
void print_rpi(rolling_proximity_identifier_t* rpi);
|
void print_rpi(rolling_proximity_identifier_t* rpi);
|
||||||
@ -52,7 +54,7 @@ int get_number_of_infected_for_period(ENPeriodKey* key, time_t timestamp);
|
|||||||
*
|
*
|
||||||
* @returns 0 in case of success, -ERRNO in case of an error
|
* @returns 0 in case of success, -ERRNO in case of an error
|
||||||
*/
|
*/
|
||||||
int get_number_of_infected_for_multiple_intervals(infected_for_period_key_ctx_t* ctx, int count);
|
// int get_number_of_infected_for_multiple_intervals(infected_for_period_key_ctx_t* ctx, int count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup fixed test data for storage.
|
* Setup fixed test data for storage.
|
||||||
|
Loading…
Reference in New Issue
Block a user