mirror of
https://github.com/CovidBraceletPrj/CovidBracelet.git
synced 2024-12-04 16:45: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;
|
||||
}
|
||||
|
||||
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;
|
||||
int i = 0;
|
||||
while (i < count) {
|
||||
@ -84,6 +124,29 @@ int get_number_of_infected_for_multiple_intervals(infected_for_period_key_ctx_t*
|
||||
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() {
|
||||
ENPeriodKey infectedPeriodKey = {
|
||||
.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);
|
||||
}
|
||||
|
||||
int infectedCount = 36;
|
||||
int spread = 2;
|
||||
|
||||
// setup our ordered array with infected RPIs
|
||||
infected_for_period_key_ctx_t infectedIntervals[10];
|
||||
for (int i = 0; i < 10; i++) {
|
||||
infected_for_period_key_ctx_t infectedIntervals[infectedCount * spread];
|
||||
for (int i = 0; i < infectedCount; i++) {
|
||||
int intervalNumber = (i + 2) * 2;
|
||||
float offset = 1.5;
|
||||
infectedIntervals[i].infected = 0;
|
||||
infectedIntervals[i].search_start =
|
||||
(intervalNumber - offset) * EN_INTERVAL_LENGTH; // start one and a half interval before
|
||||
infectedIntervals[i].search_end =
|
||||
(intervalNumber + offset) * EN_INTERVAL_LENGTH; // end one and a half interval after
|
||||
en_derive_interval_identifier((ENIntervalIdentifier*)&infectedIntervals[i].interval_identifier, &infectedPik,
|
||||
intervalNumber);
|
||||
float range = 1.5;
|
||||
for (int j = 0; j < spread; j++) {
|
||||
int offset = (EN_INTERVAL_LENGTH / spread) * j;
|
||||
infectedIntervals[i * spread + j].infected = 0;
|
||||
infectedIntervals[i * spread + j].search_start =
|
||||
(intervalNumber - range) * EN_INTERVAL_LENGTH + offset; // start one and a half interval before
|
||||
infectedIntervals[i * spread + j].search_end =
|
||||
(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");
|
||||
|
||||
timing_t start_time, end_time;
|
||||
uint64_t total_cycles;
|
||||
uint64_t total_ns;
|
||||
|
||||
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);
|
||||
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,
|
||||
infectedCount * spread);
|
||||
measure_perf(get_number_of_infected_for_multiple_intervals_optimized, "optimized", infectedIntervals,
|
||||
infectedCount * spread);
|
||||
}
|
||||
|
@ -20,7 +20,9 @@ typedef struct infected_for_period_key_ctx {
|
||||
int infected;
|
||||
time_t search_start;
|
||||
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_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
|
||||
*/
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user