Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
feat(test): Implement time utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrvivian committed Mar 27, 2019
1 parent cd08c4d commit 7407a39
Showing 1 changed file with 29 additions and 49 deletions.
78 changes: 29 additions & 49 deletions tests/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,29 @@ double diff_time(struct timespec start, struct timespec end) {
return (diff.tv_sec + diff.tv_nsec / 1000000000.0);
}

void test_time_start(struct timespec* start) {
clock_gettime(CLOCK_REALTIME, start);
}

void test_time_end(struct timespec* start, struct timespec* end, double* sum) {
clock_gettime(CLOCK_REALTIME, end);
double difference = diff_time(*start, *end);
#if defined(ENABLE_STAT)
printf("%lf\n", difference);
#endif
*sum += difference;
}

void test_generate_address(void) {
char* json_result;
double sum = 0;

for (size_t count = 0; count < TEST_COUNT; count++) {
clock_gettime(CLOCK_REALTIME, &start_time);
test_time_start(&start_time);
TEST_ASSERT_FALSE(
api_generate_address(&ta_core.tangle, &ta_core.service, &json_result));
clock_gettime(CLOCK_REALTIME, &end_time);
test_time_end(&start_time, &end_time, &sum);
free(json_result);
#if defined(ENABLE_STAT)
printf("%lf\n", diff_time(start_time, end_time));
#endif
sum += diff_time(start_time, end_time);
}
printf("Average time of generate_address: %lf\n", sum / TEST_COUNT);
}
Expand All @@ -46,15 +55,11 @@ void test_get_tips_pair(void) {
double sum = 0;

for (size_t count = 0; count < TEST_COUNT; count++) {
clock_gettime(CLOCK_REALTIME, &start_time);
test_time_start(&start_time);
TEST_ASSERT_FALSE(
api_get_tips_pair(&ta_core.tangle, &ta_core.service, &json_result));
clock_gettime(CLOCK_REALTIME, &end_time);
test_time_end(&start_time, &end_time, &sum);
free(json_result);
#if defined(ENABLE_STAT)
printf("%lf\n", diff_time(start_time, end_time));
#endif
sum += diff_time(start_time, end_time);
}
printf("Average time of get_tips_pair: %lf\n", sum / TEST_COUNT);
}
Expand All @@ -64,14 +69,10 @@ void test_get_tips(void) {
double sum = 0;

for (size_t count = 0; count < TEST_COUNT; count++) {
clock_gettime(CLOCK_REALTIME, &start_time);
test_time_start(&start_time);
TEST_ASSERT_FALSE(api_get_tips(&ta_core.service, &json_result));
clock_gettime(CLOCK_REALTIME, &end_time);
test_time_end(&start_time, &end_time, &sum);
free(json_result);
#if defined(ENABLE_STAT)
printf("%lf\n", diff_time(start_time, end_time));
#endif
sum += diff_time(start_time, end_time);
}
printf("Average time of get_tips: %lf\n", sum / TEST_COUNT);
}
Expand All @@ -86,15 +87,11 @@ void test_send_transfer(void) {
double sum = 0;

for (size_t count = 0; count < TEST_COUNT; count++) {
clock_gettime(CLOCK_REALTIME, &start_time);
test_time_start(&start_time);
TEST_ASSERT_FALSE(api_send_transfer(&ta_core.tangle, &ta_core.service, json,
&json_result));
clock_gettime(CLOCK_REALTIME, &end_time);
test_time_end(&start_time, &end_time, &sum);
free(json_result);
#if defined(ENABLE_STAT)
printf("%lf\n", diff_time(start_time, end_time));
#endif
sum += diff_time(start_time, end_time);
}
printf("Average time of send_transfer: %lf\n", sum / TEST_COUNT);
}
Expand All @@ -103,17 +100,12 @@ void test_get_transaction_object(void) {
char* json_result;
double sum = 0;

clock_gettime(CLOCK_REALTIME, &start_time);
for (size_t count = 0; count < TEST_COUNT; count++) {
clock_gettime(CLOCK_REALTIME, &start_time);
test_time_start(&start_time);
TEST_ASSERT_FALSE(api_get_transaction_object(&ta_core.service, TRYTES_81_3,
&json_result));
clock_gettime(CLOCK_REALTIME, &end_time);
test_time_end(&start_time, &end_time, &sum);
free(json_result);
#if defined(ENABLE_STAT)
printf("%lf\n", diff_time(start_time, end_time));
#endif
sum += diff_time(start_time, end_time);
}
printf("Average time of get_transaction_object: %lf\n", sum / TEST_COUNT);
}
Expand All @@ -123,15 +115,11 @@ void test_find_transactions_by_tag(void) {
double sum = 0;

for (size_t count = 0; count < TEST_COUNT; count++) {
clock_gettime(CLOCK_REALTIME, &start_time);
test_time_start(&start_time);
TEST_ASSERT_FALSE(api_find_transactions_by_tag(&ta_core.service,
FIND_TAG_MSG, &json_result));
clock_gettime(CLOCK_REALTIME, &end_time);
test_time_end(&start_time, &end_time, &sum);
free(json_result);
#if defined(ENABLE_STAT)
printf("%lf\n", diff_time(start_time, end_time));
#endif
sum += diff_time(start_time, end_time);
}
printf("Average time of find_transactions_by_tag: %lf\n", sum / TEST_COUNT);
}
Expand All @@ -141,15 +129,11 @@ void test_find_transactions_obj_by_tag(void) {
double sum = 0;

for (size_t count = 0; count < TEST_COUNT; count++) {
clock_gettime(CLOCK_REALTIME, &start_time);
test_time_start(&start_time);
TEST_ASSERT_FALSE(api_find_transactions_obj_by_tag(
&ta_core.service, FIND_TAG_MSG, &json_result));
clock_gettime(CLOCK_REALTIME, &end_time);
test_time_end(&start_time, &end_time, &sum);
free(json_result);
#if defined(ENABLE_STAT)
printf("%lf\n", diff_time(start_time, end_time));
#endif
sum += diff_time(start_time, end_time);
}
printf("Average time of find_tx_obj_by_tag: %lf\n", sum / TEST_COUNT);
}
Expand All @@ -159,15 +143,11 @@ void test_receive_mam_message(void) {
double sum = 0;

for (size_t count = 0; count < TEST_COUNT; count++) {
clock_gettime(CLOCK_REALTIME, &start_time);
test_time_start(&start_time);
TEST_ASSERT_FALSE(
api_receive_mam_message(&ta_core.service, BUNDLE_HASH, &json_result));
clock_gettime(CLOCK_REALTIME, &end_time);
test_time_end(&start_time, &end_time, &sum);
free(json_result);
#if defined(ENABLE_STAT)
printf("%lf\n", diff_time(start_time, end_time));
#endif
sum += diff_time(start_time, end_time);
}
printf("Average time of receive_mam_message: %lf\n", sum / TEST_COUNT);
}
Expand Down

0 comments on commit 7407a39

Please sign in to comment.