From 4b61011e032fae556133860827e39324322a1197 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Fri, 11 Oct 2024 10:52:20 -0600 Subject: [PATCH 01/10] adding benchmark cases --- code/tests/test_arrayof.c | 75 +++++ code/tests/test_doublylist.c | 94 +++++++ code/tests/test_dqueue.c | 108 +++++++ code/tests/test_forwardlist.c | 95 +++++++ code/tests/test_mapof.c | 76 +++++ code/tests/test_pqueue.c | 109 +++++++ code/tests/test_queue.c | 88 ++++++ code/tests/test_setof.c | 88 ++++++ code/tests/test_stack.c | 67 +++++ code/tests/test_tofu.c | 515 ++++++++++++++++++++++++++++++++++ code/tests/test_vector.c | 157 +++++++++++ 11 files changed, 1472 insertions(+) diff --git a/code/tests/test_arrayof.c b/code/tests/test_arrayof.c index 95eee20..bb15b3a 100644 --- a/code/tests/test_arrayof.c +++ b/code/tests/test_arrayof.c @@ -12,6 +12,7 @@ * ----------------------------------------------------------------------------- */ #include +#include #include #include "fossil/tofu/framework.h" @@ -81,6 +82,72 @@ FOSSIL_TEST(test_fossil_tofu_arrayof_clear) { fossil_tofu_arrayof_erase(&array); } +// benchmarking cases to capture the true +// performence based on current structures +// implmentation. + +FOSSIL_TEST(benchmark_fossil_tofu_arrayof_create) { + MARK_START(fossil_tofu_arrayof_create); + for (size_t i = 0; i < 1000000; i++) { + fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 3, "10", "20", "30"); + fossil_tofu_arrayof_erase(&array); + } + MARK_STOP(fossil_tofu_arrayof_create); +} + +FOSSIL_TEST(benchmark_fossil_tofu_arrayof_add) { + MARK_START(fossil_tofu_arrayof_add); + for (size_t i = 0; i < 1000000; i++) { + fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 0); + fossil_tofu_t tofu1 = fossil_tofu_create("int", "10"); + fossil_tofu_t tofu2 = fossil_tofu_create("int", "20"); + fossil_tofu_arrayof_add(&array, tofu1); + fossil_tofu_arrayof_add(&array, tofu2); + fossil_tofu_arrayof_erase(&array); + } + MARK_STOP(fossil_tofu_arrayof_add); +} + +FOSSIL_TEST(benchmark_fossil_tofu_arrayof_get) { + MARK_START(fossil_tofu_arrayof_get); + for (size_t i = 0; i < 1000000; i++) { + fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 3, "10", "20", "30"); + fossil_tofu_t tofu = fossil_tofu_arrayof_get(&array, 1); + fossil_tofu_arrayof_erase(&array); + } + MARK_STOP(fossil_tofu_arrayof_get); +} + +FOSSIL_TEST(benchmark_fossil_tofu_arrayof_size) { + MARK_START(fossil_tofu_arrayof_size); + for (size_t i = 0; i < 1000000; i++) { + fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 2, "10", "20"); + fossil_tofu_arrayof_size(&array); + fossil_tofu_arrayof_erase(&array); + } + MARK_STOP(fossil_tofu_arrayof_size); +} + +FOSSIL_TEST(benchmark_fossil_tofu_arrayof_is_empty) { + MARK_START(fossil_tofu_arrayof_is_empty); + for (size_t i = 0; i < 1000000; i++) { + fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 0); + fossil_tofu_arrayof_is_empty(&array); + fossil_tofu_arrayof_erase(&array); + } + MARK_STOP(fossil_tofu_arrayof_is_empty); +} + +FOSSIL_TEST(benchmark_fossil_tofu_arrayof_clear) { + MARK_START(fossil_tofu_arrayof_clear); + for (size_t i = 0; i < 1000000; i++) { + fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 3, "10", "20", "30"); + fossil_tofu_arrayof_clear(&array); + fossil_tofu_arrayof_erase(&array); + } + MARK_STOP(fossil_tofu_arrayof_clear); +} + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -92,4 +159,12 @@ FOSSIL_TEST_GROUP(c_arrayof_structure_tests) { ADD_TEST(test_fossil_tofu_arrayof_size); ADD_TEST(test_fossil_tofu_arrayof_is_empty); ADD_TEST(test_fossil_tofu_arrayof_clear); + + // Benchmarking + ADD_TEST(benchmark_fossil_tofu_arrayof_create); + ADD_TEST(benchmark_fossil_tofu_arrayof_add); + ADD_TEST(benchmark_fossil_tofu_arrayof_get); + ADD_TEST(benchmark_fossil_tofu_arrayof_size); + ADD_TEST(benchmark_fossil_tofu_arrayof_is_empty); + ADD_TEST(benchmark_fossil_tofu_arrayof_clear); } // end of tests diff --git a/code/tests/test_doublylist.c b/code/tests/test_doublylist.c index 0b4663b..d5310cb 100644 --- a/code/tests/test_doublylist.c +++ b/code/tests/test_doublylist.c @@ -12,6 +12,7 @@ * ----------------------------------------------------------------------------- */ #include +#include #include #include "fossil/tofu/framework.h" @@ -133,6 +134,94 @@ FOSSIL_TEST(test_dlist_reverse_backward) { ASSUME_ITS_EQUAL_I32(42, retrievedElement->value.int_val); } +// benchmarking cases to capture the true +// performence based on current structures +// implmentation. + +FOSSIL_TEST(benchmark_dlist_insert) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Start the benchmark + MARK_START(dlist_insert); + + // Insert the element + fossil_dlist_insert(mock_dlist, element); + + // Stop the benchmark + MARK_STOP(dlist_insert); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_dlist_remove) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_dlist_insert(mock_dlist, element); + + // Start the benchmark + MARK_START(dlist_remove); + + // Remove the element + fossil_tofu_t removedElement; + fossil_dlist_remove(mock_dlist, &removedElement); + + // Stop the benchmark + MARK_STOP(dlist_remove); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_dlist_reverse_forward) { + // Insert some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_dlist_insert(mock_dlist, element1); + fossil_dlist_insert(mock_dlist, element2); + fossil_dlist_insert(mock_dlist, element3); + + // Start the benchmark + MARK_START(dlist_reverse_forward); + + // Reverse the doubly linked list forward + fossil_dlist_reverse_forward(mock_dlist); + + // Stop the benchmark + MARK_STOP(dlist_reverse_forward); + + fossil_tofu_erase(&element1); + fossil_tofu_erase(&element2); + fossil_tofu_erase(&element3); +} + +FOSSIL_TEST(benchmark_dlist_reverse_backward) { + // Insert some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_dlist_insert(mock_dlist, element1); + fossil_dlist_insert(mock_dlist, element2); + fossil_dlist_insert(mock_dlist, element3); + + // Start the benchmark + MARK_START(dlist_reverse_backward); + + // Reverse the doubly linked list backward + fossil_dlist_reverse_backward(mock_dlist); + + // Stop the benchmark + MARK_STOP(dlist_reverse_backward); + + fossil_tofu_erase(&element1); + fossil_tofu_erase(&element2); + fossil_tofu_erase(&element3); +} + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -143,4 +232,9 @@ FOSSIL_TEST_GROUP(c_dlist_structure_tests) { ADD_TESTF(test_dlist_remove, struct_dlist_fixture); ADD_TESTF(test_dlist_reverse_forward, struct_dlist_fixture); ADD_TESTF(test_dlist_reverse_backward, struct_dlist_fixture); + + ADD_TESTF(benchmark_dlist_insert, struct_dlist_fixture); + ADD_TESTF(benchmark_dlist_remove, struct_dlist_fixture); + ADD_TESTF(benchmark_dlist_reverse_forward, struct_dlist_fixture); + ADD_TESTF(benchmark_dlist_reverse_backward, struct_dlist_fixture); } // end of tests diff --git a/code/tests/test_dqueue.c b/code/tests/test_dqueue.c index 571bbb7..7b6e9fb 100644 --- a/code/tests/test_dqueue.c +++ b/code/tests/test_dqueue.c @@ -12,7 +12,9 @@ * ----------------------------------------------------------------------------- */ #include +#include #include + #include // * * * * * * * * * * * * * * * * * * * * * * * * @@ -125,6 +127,105 @@ FOSSIL_TEST(test_dqueue_not_empty_and_is_empty) { ASSUME_ITS_TRUE(fossil_dqueue_is_empty(mock_dqueue)); } +// benchmarking cases to capture the true +// performence based on current structures +// implmentation. + +FOSSIL_TEST(benchmark_dqueue_insert) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Start the benchmark + MARK_START(dqueue_insert); + + // Insert the element + fossil_dqueue_insert(mock_dqueue, element); + + // Stop the benchmark + MARK_STOP(dqueue_insert); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_dqueue_remove) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_dqueue_insert(mock_dqueue, element); + + // Start the benchmark + MARK_START(dqueue_remove); + + // Remove the element + fossil_tofu_t removedElement; + fossil_dqueue_remove(mock_dqueue, &removedElement); + + // Stop the benchmark + MARK_STOP(dqueue_remove); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_dqueue_size) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_dqueue_insert(mock_dqueue, element); + + // Start the benchmark + MARK_START(dqueue_size); + + // Get the size + fossil_dqueue_size(mock_dqueue); + + // Stop the benchmark + MARK_STOP(dqueue_size); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_dqueue_not_empty) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_dqueue_insert(mock_dqueue, element); + + // Start the benchmark + MARK_START(dqueue_not_empty); + + for (size_t i = 0; i < 1000000; i++) { + fossil_dqueue_not_empty(mock_dqueue); + } + + // Stop the benchmark + MARK_STOP(dqueue_not_empty); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_dqueue_is_empty) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_dqueue_insert(mock_dqueue, element); + + // Start the benchmark + MARK_START(dqueue_is_empty); + + for (size_t i = 0; i < 1000000; i++) { + fossil_dqueue_is_empty(mock_dqueue); + } + + // Stop the benchmark + MARK_STOP(dqueue_is_empty); + + fossil_tofu_erase(&element); +} + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -134,4 +235,11 @@ FOSSIL_TEST_GROUP(c_dqueue_structure_tests) { ADD_TESTF(test_dqueue_remove, struct_dqueue_fixture); //ADD_TESTF(test_dqueue_getter_and_setter, struct_dqueue_fixture); ADD_TESTF(test_dqueue_not_empty_and_is_empty, struct_dqueue_fixture); + + // Benchmarking cases + ADD_TEST(benchmark_dqueue_insert); + ADD_TEST(benchmark_dqueue_remove); + ADD_TEST(benchmark_dqueue_size); + ADD_TEST(benchmark_dqueue_not_empty); + ADD_TEST(benchmark_dqueue_is_empty); } // end of tests diff --git a/code/tests/test_forwardlist.c b/code/tests/test_forwardlist.c index e3c9280..ed0f777 100644 --- a/code/tests/test_forwardlist.c +++ b/code/tests/test_forwardlist.c @@ -12,6 +12,7 @@ * ----------------------------------------------------------------------------- */ #include +#include #include #include "fossil/tofu/framework.h" @@ -136,6 +137,94 @@ FOSSIL_TEST(test_flist_reverse_backward) { ASSUME_ITS_EQUAL_I32(42, retrievedElement->value.int_val); } +// benchmarking cases to capture the true +// performence based on current structures +// implmentation. + +FOSSIL_TEST(benchmark_flist_insert) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Start the benchmark + MARK_START(flist_insert); + + // Insert the element + fossil_flist_insert(mock_flist, element); + + // Stop the benchmark + MARK_STOP(flist_insert); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_flist_remove) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_flist_insert(mock_flist, element); + + // Start the benchmark + MARK_START(flist_remove); + + // Remove the element + fossil_tofu_t removedElement; + fossil_flist_remove(mock_flist, &removedElement); + + // Stop the benchmark + MARK_STOP(flist_remove); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_flist_reverse_forward) { + // Insert some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_flist_insert(mock_flist, element1); + fossil_flist_insert(mock_flist, element2); + fossil_flist_insert(mock_flist, element3); + + // Start the benchmark + MARK_START(flist_reverse_forward); + + // Reverse the linked list forward + fossil_flist_reverse_forward(mock_flist); + + // Stop the benchmark + MARK_STOP(flist_reverse_forward); + + fossil_tofu_erase(&element1); + fossil_tofu_erase(&element2); + fossil_tofu_erase(&element3); +} + +FOSSIL_TEST(benchmark_flist_reverse_backward) { + // Insert some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_flist_insert(mock_flist, element1); + fossil_flist_insert(mock_flist, element2); + fossil_flist_insert(mock_flist, element3); + + // Start the benchmark + MARK_START(flist_reverse_backward); + + // Reverse the linked list backward + fossil_flist_reverse_backward(mock_flist); + + // Stop the benchmark + MARK_STOP(flist_reverse_backward); + + fossil_tofu_erase(&element1); + fossil_tofu_erase(&element2); + fossil_tofu_erase(&element3); +} + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -145,4 +234,10 @@ FOSSIL_TEST_GROUP(c_flist_structure_tests) { ADD_TESTF(test_flist_remove, struct_flist_fixture); ADD_TESTF(test_flist_reverse_forward, struct_flist_fixture); ADD_TESTF(test_flist_reverse_backward, struct_flist_fixture); + + // Benchmarking cases + ADD_TEST(benchmark_flist_insert); + ADD_TEST(benchmark_flist_remove); + ADD_TEST(benchmark_flist_reverse_forward); + ADD_TEST(benchmark_flist_reverse_backward); } // end of tests diff --git a/code/tests/test_mapof.c b/code/tests/test_mapof.c index db92d3a..686e264 100644 --- a/code/tests/test_mapof.c +++ b/code/tests/test_mapof.c @@ -12,6 +12,7 @@ * ----------------------------------------------------------------------------- */ #include +#include #include #include "fossil/tofu/framework.h" @@ -101,6 +102,74 @@ FOSSIL_TEST(test_fossil_tofu_mapof_clear) { fossil_tofu_mapof_erase(&map); } +// benchmarking cases to capture the true +// performence based on current structures +// implmentation. + +FOSSIL_TEST(benchmark_fossil_tofu_mapof_create) { + MARK_START(fossil_tofu_mapof_create); + for (size_t i = 0; i < 1000000; i++) { + fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); + fossil_tofu_mapof_erase(&map); + } + MARK_STOP(fossil_tofu_mapof_create); +} + +FOSSIL_TEST(benchmark_fossil_tofu_mapof_add_and_get) { + MARK_START(fossil_tofu_mapof_add_and_get); + for (size_t i = 0; i < 1000000; i++) { + fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); + fossil_tofu_t key = fossil_tofu_create("int", "1"); + fossil_tofu_t value = fossil_tofu_create("int", "100"); + fossil_tofu_mapof_add(&map, key, value); + fossil_tofu_t retrieved = fossil_tofu_mapof_get(&map, key); + fossil_tofu_mapof_erase(&map); + } + MARK_STOP(fossil_tofu_mapof_add_and_get); +} + +FOSSIL_TEST(benchmark_fossil_tofu_mapof_contains) { + MARK_START(fossil_tofu_mapof_contains); + for (size_t i = 0; i < 1000000; i++) { + fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); + fossil_tofu_t key = fossil_tofu_create("int", "1"); + fossil_tofu_t value = fossil_tofu_create("int", "100"); + fossil_tofu_mapof_add(&map, key, value); + fossil_tofu_mapof_contains(&map, key); + fossil_tofu_mapof_erase(&map); + } + MARK_STOP(fossil_tofu_mapof_contains); +} + +FOSSIL_TEST(benchmark_fossil_tofu_mapof_remove) { + MARK_START(fossil_tofu_mapof_remove); + for (size_t i = 0; i < 1000000; i++) { + fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); + fossil_tofu_t key = fossil_tofu_create("int", "1"); + fossil_tofu_t value = fossil_tofu_create("int", "100"); + fossil_tofu_mapof_add(&map, key, value); + fossil_tofu_mapof_remove(&map, key); + fossil_tofu_mapof_erase(&map); + } + MARK_STOP(fossil_tofu_mapof_remove); +} + +FOSSIL_TEST(benchmark_fossil_tofu_mapof_size) { + MARK_START(fossil_tofu_mapof_size); + for (size_t i = 0; i < 1000000; i++) { + fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); + fossil_tofu_t key1 = fossil_tofu_create("int", "1"); + fossil_tofu_t value1 = fossil_tofu_create("int", "100"); + fossil_tofu_t key2 = fossil_tofu_create("int", "2"); + fossil_tofu_t value2 = fossil_tofu_create("int", "200"); + fossil_tofu_mapof_add(&map, key1, value1); + fossil_tofu_mapof_add(&map, key2, value2); + fossil_tofu_mapof_size(&map); + fossil_tofu_mapof_erase(&map); + } + MARK_STOP(fossil_tofu_mapof_size); +} + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -113,4 +182,11 @@ FOSSIL_TEST_GROUP(c_mapof_structure_tests) { ADD_TEST(test_fossil_tofu_mapof_size); ADD_TEST(test_fossil_tofu_mapof_is_empty); ADD_TEST(test_fossil_tofu_mapof_clear); + + // Benchmarking + ADD_TEST(benchmark_fossil_tofu_mapof_create); + ADD_TEST(benchmark_fossil_tofu_mapof_add_and_get); + ADD_TEST(benchmark_fossil_tofu_mapof_contains); + ADD_TEST(benchmark_fossil_tofu_mapof_remove); + ADD_TEST(benchmark_fossil_tofu_mapof_size); } // end of tests diff --git a/code/tests/test_pqueue.c b/code/tests/test_pqueue.c index cf97f64..c8b98c6 100644 --- a/code/tests/test_pqueue.c +++ b/code/tests/test_pqueue.c @@ -12,6 +12,7 @@ * ----------------------------------------------------------------------------- */ #include +#include #include #include "fossil/tofu/framework.h" @@ -96,6 +97,107 @@ FOSSIL_TEST(test_pqueue_not_empty_and_is_empty) { ASSUME_ITS_TRUE(fossil_pqueue_remove(mock_pqueue, &removedElement, removedPriority)); } +// benchmarking cases to capture the true +// performence based on current structures +// implmentation. + +FOSSIL_TEST(benchmark_pqueue_insert) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Start the benchmark + MARK_START(pqueue_insert); + + for (size_t i = 0; i < 1000000; i++) { + fossil_pqueue_insert(mock_pqueue, element, 2); + } + + // Stop the benchmark + MARK_STOP(pqueue_insert); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_pqueue_remove) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_pqueue_insert(mock_pqueue, element, 2); + + // Start the benchmark + MARK_START(pqueue_remove); + + for (size_t i = 0; i < 1000000; i++) { + fossil_pqueue_remove(mock_pqueue, &element, 0); + } + + // Stop the benchmark + MARK_STOP(pqueue_remove); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_pqueue_size) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_pqueue_insert(mock_pqueue, element, 2); + + // Start the benchmark + MARK_START(pqueue_size); + + for (size_t i = 0; i < 1000000; i++) { + fossil_pqueue_size(mock_pqueue); + } + + // Stop the benchmark + MARK_STOP(pqueue_size); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_pqueue_not_empty) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_pqueue_insert(mock_pqueue, element, 2); + + // Start the benchmark + MARK_START(pqueue_not_empty); + + for (size_t i = 0; i < 1000000; i++) { + fossil_pqueue_not_empty(mock_pqueue); + } + + // Stop the benchmark + MARK_STOP(pqueue_not_empty); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_pqueue_is_empty) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_pqueue_insert(mock_pqueue, element, 2); + + // Start the benchmark + MARK_START(pqueue_is_empty); + + for (size_t i = 0; i < 1000000; i++) { + fossil_pqueue_is_empty(mock_pqueue); + } + + // Stop the benchmark + MARK_STOP(pqueue_is_empty); + + fossil_tofu_erase(&element); +} + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -105,4 +207,11 @@ FOSSIL_TEST_GROUP(c_pqueue_structure_tests) { ADD_TESTF(test_pqueue_insert_and_size, struct_pqueue_fixture); ADD_TESTF(test_pqueue_remove, struct_pqueue_fixture); ADD_TESTF(test_pqueue_not_empty_and_is_empty, struct_pqueue_fixture); + + // Benchmarking + ADD_TESTF(benchmark_pqueue_insert, struct_pqueue_fixture); + ADD_TESTF(benchmark_pqueue_remove, struct_pqueue_fixture); + ADD_TESTF(benchmark_pqueue_size, struct_pqueue_fixture); + ADD_TESTF(benchmark_pqueue_not_empty, struct_pqueue_fixture); + ADD_TESTF(benchmark_pqueue_is_empty, struct_pqueue_fixture); } // end of tests diff --git a/code/tests/test_queue.c b/code/tests/test_queue.c index fcb28f6..ade88e4 100644 --- a/code/tests/test_queue.c +++ b/code/tests/test_queue.c @@ -12,6 +12,7 @@ * ----------------------------------------------------------------------------- */ #include +#include #include #include "fossil/tofu/framework.h" @@ -104,6 +105,87 @@ FOSSIL_TEST(test_queue_not_empty_and_is_empty) { fossil_tofu_erase(&element); } +// benchmarking cases to capture the true +// performence based on current structures +// implmentation. + +FOSSIL_TEST(benchmark_queue_insert) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Start the benchmark + MARK_START(queue_insert); + + for (size_t i = 0; i < 1000000; i++) { + fossil_queue_insert(mock_queue, element); + } + + // Stop the benchmark + MARK_STOP(queue_insert); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_queue_remove) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_queue_insert(mock_queue, element); + + // Start the benchmark + MARK_START(queue_remove); + + for (size_t i = 0; i < 1000000; i++) { + fossil_queue_remove(mock_queue, &element); + } + + // Stop the benchmark + MARK_STOP(queue_remove); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_queue_size) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_queue_insert(mock_queue, element); + + // Start the benchmark + MARK_START(queue_size); + + for (size_t i = 0; i < 1000000; i++) { + fossil_queue_size(mock_queue); + } + + // Stop the benchmark + MARK_STOP(queue_size); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_queue_not_empty) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_queue_insert(mock_queue, element); + + // Start the benchmark + MARK_START(queue_not_empty); + + for (size_t i = 0; i < 1000000; i++) { + fossil_queue_not_empty(mock_queue); + } + + // Stop the benchmark + MARK_STOP(queue_not_empty); + + fossil_tofu_erase(&element); +} + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -113,4 +195,10 @@ FOSSIL_TEST_GROUP(c_structure_tests) { ADD_TESTF(test_queue_insert_and_size, struct_queue_fixture); ADD_TESTF(test_queue_remove, struct_queue_fixture); ADD_TESTF(test_queue_not_empty_and_is_empty, struct_queue_fixture); + + // Benchmarking + ADD_TESTF(benchmark_queue_insert, struct_queue_fixture); + ADD_TESTF(benchmark_queue_remove, struct_queue_fixture); + ADD_TESTF(benchmark_queue_size, struct_queue_fixture); + ADD_TESTF(benchmark_queue_not_empty, struct_queue_fixture); } // end of tests diff --git a/code/tests/test_setof.c b/code/tests/test_setof.c index 4d6ac3c..b406911 100644 --- a/code/tests/test_setof.c +++ b/code/tests/test_setof.c @@ -12,6 +12,7 @@ * ----------------------------------------------------------------------------- */ #include +#include #include #include "fossil/tofu/framework.h" @@ -107,6 +108,87 @@ FOSSIL_TEST(test_set_contains) { fossil_tofu_erase(&element3); } +// benchmarking cases to capture the true +// performence based on current structures +// implmentation. + +FOSSIL_TEST(benchmark_set_insert) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Start the benchmark + MARK_START(set_insert); + + for (size_t i = 0; i < 1000000; i++) { + fossil_set_insert(mock_set, element); + } + + // Stop the benchmark + MARK_STOP(set_insert); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_set_remove) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_set_insert(mock_set, element); + + // Start the benchmark + MARK_START(set_remove); + + for (size_t i = 0; i < 1000000; i++) { + fossil_set_remove(mock_set, element); + } + + // Stop the benchmark + MARK_STOP(set_remove); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_set_size) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_set_insert(mock_set, element); + + // Start the benchmark + MARK_START(set_size); + + for (size_t i = 0; i < 1000000; i++) { + fossil_set_size(mock_set); + } + + // Stop the benchmark + MARK_STOP(set_size); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_set_contains) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_set_insert(mock_set, element); + + // Start the benchmark + MARK_START(set_contains); + + for (size_t i = 0; i < 1000000; i++) { + fossil_set_contains(mock_set, element); + } + + // Stop the benchmark + MARK_STOP(set_contains); + + fossil_tofu_erase(&element); +} + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -116,4 +198,10 @@ FOSSIL_TEST_GROUP(c_setof_structure_tests) { ADD_TESTF(test_set_insert_and_size, struct_set_fixture); ADD_TESTF(test_set_remove, struct_set_fixture); ADD_TESTF(test_set_contains, struct_set_fixture); + + // Benchmarking + ADD_TESTF(benchmark_set_insert, struct_set_fixture); + ADD_TESTF(benchmark_set_remove, struct_set_fixture); + ADD_TESTF(benchmark_set_size, struct_set_fixture); + ADD_TESTF(benchmark_set_contains, struct_set_fixture); } // end of tests diff --git a/code/tests/test_stack.c b/code/tests/test_stack.c index ac4d34e..7fdc3a0 100644 --- a/code/tests/test_stack.c +++ b/code/tests/test_stack.c @@ -12,6 +12,7 @@ * ----------------------------------------------------------------------------- */ #include +#include #include #include "fossil/tofu/framework.h" @@ -91,6 +92,67 @@ FOSSIL_TEST(test_stack_remove) { fossil_tofu_erase(&element3); } +// benchmarking cases to capture the true +// performence based on current structures +// implmentation. + +FOSSIL_TEST(benchmark_stack_insert) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Start the benchmark + MARK_START(stack_insert); + + for (size_t i = 0; i < 1000000; i++) { + fossil_stack_insert(mock_stack, element); + } + + // Stop the benchmark + MARK_STOP(stack_insert); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_stack_remove) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_stack_insert(mock_stack, element); + + // Start the benchmark + MARK_START(stack_remove); + + for (size_t i = 0; i < 1000000; i++) { + fossil_stack_remove(mock_stack, &element); + } + + // Stop the benchmark + MARK_STOP(stack_remove); + + fossil_tofu_erase(&element); +} + +FOSSIL_TEST(benchmark_stack_size) { + // Create an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Insert the element + fossil_stack_insert(mock_stack, element); + + // Start the benchmark + MARK_START(stack_size); + + for (size_t i = 0; i < 1000000; i++) { + fossil_stack_size(mock_stack); + } + + // Stop the benchmark + MARK_STOP(stack_size); + + fossil_tofu_erase(&element); +} + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -100,4 +162,9 @@ FOSSIL_TEST_GROUP(c_stack_structure_tests) { ADD_TESTF(test_stack_create_and_erase, struct_stack_fixture); ADD_TESTF(test_stack_insert_and_size, struct_stack_fixture); ADD_TESTF(test_stack_remove, struct_stack_fixture); + + // Stack Benchmark + ADD_TESTF(benchmark_stack_insert, struct_stack_fixture); + ADD_TESTF(benchmark_stack_remove, struct_stack_fixture); + ADD_TESTF(benchmark_stack_size, struct_stack_fixture); } // end of tests diff --git a/code/tests/test_tofu.c b/code/tests/test_tofu.c index 36e8908..73e1225 100644 --- a/code/tests/test_tofu.c +++ b/code/tests/test_tofu.c @@ -12,6 +12,7 @@ * ----------------------------------------------------------------------------- */ #include +#include #include #include "fossil/tofu/framework.h" @@ -277,6 +278,504 @@ FOSSIL_TEST(test_fossil_tofu_create_invalid) { ASSUME_ITS_EQUAL_I32(FOSSIL_TOFU_TYPE_GHOST, tofu_invalid_value.type); } +// benchmarking cases to capture the true +// performence based on current structures +// implmentation. + +FOSSIL_TEST(benchmark_tofu_speed_create) { + // Start the benchmark + MARK_START(tofu_speed_create); + + fossil_tofu_t tofu = fossil_tofu_create("int", "100"); + + // Stop the benchmark + MARK_STOP(tofu_speed_create); + + fossil_tofu_erase(&tofu); + +} + +FOSSIL_TEST(benchmark_tofu_speed_equals) { + // Create two tofu objects + fossil_tofu_t tofu1 = fossil_tofu_create("int", "100"); + fossil_tofu_t tofu2 = fossil_tofu_create("int", "100"); + + // Start the benchmark + MARK_START(tofu_speed_equals); + + // Compare the two tofu objects + fossil_tofu_equals(tofu1, tofu2); + + // Stop the benchmark + MARK_STOP(tofu_speed_equals); + + fossil_tofu_erase(&tofu1); + fossil_tofu_erase(&tofu2); +} + +FOSSIL_TEST(benchmark_tofu_speed_copy) { + // Create a tofu object + fossil_tofu_t tofu_orig = fossil_tofu_create("int", "100"); + + // Start the benchmark + MARK_START(tofu_speed_copy); + + // Copy the tofu object + fossil_tofu_t tofu_copy = fossil_tofu_copy(tofu_orig); + + // Stop the benchmark + MARK_STOP(tofu_speed_copy); + + fossil_tofu_erase(&tofu_orig); + fossil_tofu_erase(&tofu_copy); +} + +FOSSIL_TEST(benchmark_tofu_speed_transform) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "10"), + fossil_tofu_create("int", "20"), + fossil_tofu_create("int", "30") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_transform); + + // Transform the array + fossil_tofu_actionof_transform(array, size, double_value); + + // Stop the benchmark + MARK_STOP(tofu_speed_transform); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + +FOSSIL_TEST(benchmark_tofu_speed_accumulate) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "10"), + fossil_tofu_create("int", "20"), + fossil_tofu_create("int", "30") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Create an initial tofu object + fossil_tofu_t init = fossil_tofu_create("int", "0"); + + // Start the benchmark + MARK_START(tofu_speed_accumulate); + + // Accumulate the array + fossil_tofu_actionof_accumulate(array, size, init, sum); + + // Stop the benchmark + MARK_STOP(tofu_speed_accumulate); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } + fossil_tofu_erase(&init); +} + +FOSSIL_TEST(benchmark_tofu_speed_filter) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "10"), + fossil_tofu_create("int", "20"), + fossil_tofu_create("int", "30") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_filter); + + // Filter the array + fossil_tofu_actionof_filter(array, size, tofu_mock_is_even); + + // Stop the benchmark + MARK_STOP(tofu_speed_filter); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + +FOSSIL_TEST(benchmark_tofu_speed_reverse) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "10"), + fossil_tofu_create("int", "20"), + fossil_tofu_create("int", "30") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_reverse); + + // Reverse the array + fossil_tofu_actionof_reverse(array, size); + + // Stop the benchmark + MARK_STOP(tofu_speed_reverse); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + +FOSSIL_TEST(benchmark_tofu_speed_swap) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "10"), + fossil_tofu_create("int", "20"), + fossil_tofu_create("int", "30") + }; + + // Start the benchmark + MARK_START(tofu_speed_swap); + + // Swap two tofu objects + fossil_tofu_actionof_swap(array, 0, 2); + + // Stop the benchmark + MARK_STOP(tofu_speed_swap); + + // Erase the tofu objects + for (size_t i = 0; i < 3; i++) { + fossil_tofu_erase(&array[i]); + } +} + +FOSSIL_TEST(benchmark_tofu_speed_reduce) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "10"), + fossil_tofu_create("int", "20"), + fossil_tofu_create("int", "30") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_reduce); + + // Reduce the array + fossil_tofu_actionof_reduce(array, size, sum_function); + + // Stop the benchmark + MARK_STOP(tofu_speed_reduce); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + +// Test case for benchmarking the average function +FOSSIL_TEST(benchmark_tofu_speed_average) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "10"), + fossil_tofu_create("int", "20"), + fossil_tofu_create("int", "30") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_average); + + // Calculate the average of the array + fossil_tofu_actionof_average(array, size); + + // Stop the benchmark + MARK_STOP(tofu_speed_average); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + +// Test case for benchmarking the shuffle function +FOSSIL_TEST(benchmark_tofu_speed_shuffle) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "10"), + fossil_tofu_create("int", "20"), + fossil_tofu_create("int", "30") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_shuffle); + + // Shuffle the array + fossil_tofu_actionof_shuffle(array, size); + + // Stop the benchmark + MARK_STOP(tofu_speed_shuffle); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + +// Test case for benchmarking the for_each function +FOSSIL_TEST(benchmark_tofu_speed_for_each) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "10"), + fossil_tofu_create("int", "20"), + fossil_tofu_create("int", "30") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_for_each); + + // Apply a function to each element in the array + fossil_tofu_actionof_for_each(array, size, double_value); + + // Stop the benchmark + MARK_STOP(tofu_speed_for_each); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + +// Test case for benchmarking the partition function +FOSSIL_TEST(benchmark_tofu_speed_partition) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "10"), + fossil_tofu_create("int", "20"), + fossil_tofu_create("int", "30"), + fossil_tofu_create("int", "40"), + fossil_tofu_create("int", "50"), + fossil_tofu_create("int", "60"), + fossil_tofu_create("int", "70"), + fossil_tofu_create("int", "80"), + fossil_tofu_create("int", "90"), + fossil_tofu_create("int", "100") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_partition); + + // Partition the array + fossil_tofu_actionof_partition(array, size, tofu_mock_is_even); + + // Stop the benchmark + MARK_STOP(tofu_speed_partition); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + +// Test case for benchmarking the summary function +FOSSIL_TEST(benchmark_tofu_speed_summary) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "10"), + fossil_tofu_create("int", "20"), + fossil_tofu_create("int", "30"), + fossil_tofu_create("int", "40"), + fossil_tofu_create("int", "50"), + fossil_tofu_create("int", "60"), + fossil_tofu_create("int", "70"), + fossil_tofu_create("int", "80"), + fossil_tofu_create("int", "90"), + fossil_tofu_create("int", "100") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_summary); + + // Calculate the summary of the array + fossil_tofu_actionof_summary(array, size, sum_function); + + // Stop the benchmark + MARK_STOP(tofu_speed_summary); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + +// Test case for benchmarking the average function +FOSSIL_TEST(benchmark_tofu_speed_average) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "10"), + fossil_tofu_create("int", "20"), + fossil_tofu_create("int", "30"), + fossil_tofu_create("int", "40"), + fossil_tofu_create("int", "50"), + fossil_tofu_create("int", "60"), + fossil_tofu_create("int", "70"), + fossil_tofu_create("int", "80"), + fossil_tofu_create("int", "90"), + fossil_tofu_create("int", "100") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_average); + + // Calculate the average of the array + fossil_tofu_actionof_average(array, size); + + // Stop the benchmark + MARK_STOP(tofu_speed_average); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + +// Test case for benchmarking the shuffle function +FOSSIL_TEST(benchmark_tofu_speed_shuffle) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "1"), + fossil_tofu_create("int", "2"), + fossil_tofu_create("int", "3"), + fossil_tofu_create("int", "4"), + fossil_tofu_create("int", "5"), + fossil_tofu_create("int", "6"), + fossil_tofu_create("int", "7"), + fossil_tofu_create("int", "8"), + fossil_tofu_create("int", "9"), + fossil_tofu_create("int", "10") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_shuffle); + + // Shuffle the array + fossil_tofu_actionof_shuffle(array, size); + + // Stop the benchmark + MARK_STOP(tofu_speed_shuffle); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + +// Test case for benchmarking the for_each function +FOSSIL_TEST(benchmark_tofu_speed_for_each) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "1"), + fossil_tofu_create("int", "2"), + fossil_tofu_create("int", "3"), + fossil_tofu_create("int", "4"), + fossil_tofu_create("int", "5"), + fossil_tofu_create("int", "6"), + fossil_tofu_create("int", "7"), + fossil_tofu_create("int", "8"), + fossil_tofu_create("int", "9"), + fossil_tofu_create("int", "10") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_for_each); + + // Apply a function to each element in the array + fossil_tofu_actionof_for_each(array, size, double_value); + + // Stop the benchmark + MARK_STOP(tofu_speed_for_each); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + +// Test case for benchmarking the partition function +FOSSIL_TEST(benchmark_tofu_speed_partition) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "1"), + fossil_tofu_create("int", "2"), + fossil_tofu_create("int", "3"), + fossil_tofu_create("int", "4"), + fossil_tofu_create("int", "5"), + fossil_tofu_create("int", "6"), + fossil_tofu_create("int", "7"), + fossil_tofu_create("int", "8"), + fossil_tofu_create("int", "9"), + fossil_tofu_create("int", "10") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_partition); + + // Partition the array + fossil_tofu_actionof_partition(array, size, tofu_mock_is_even); + + // Stop the benchmark + MARK_STOP(tofu_speed_partition); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + +// Test case for benchmarking the summary function +FOSSIL_TEST(benchmark_tofu_speed_summary) { + // Create an array of tofu objects + fossil_tofu_t array[] = { + fossil_tofu_create("int", "1"), + fossil_tofu_create("int", "2"), + fossil_tofu_create("int", "3"), + fossil_tofu_create("int", "4"), + fossil_tofu_create("int", "5"), + fossil_tofu_create("int", "6"), + fossil_tofu_create("int", "7"), + fossil_tofu_create("int", "8"), + fossil_tofu_create("int", "9"), + fossil_tofu_create("int", "10") + }; + size_t size = sizeof(array) / sizeof(array[0]); + + // Start the benchmark + MARK_START(tofu_speed_summary); + + // Calculate the summary of the array + fossil_tofu_actionof_summary(array, size, sum_function); + + // Stop the benchmark + MARK_STOP(tofu_speed_summary); + + // Erase the tofu objects + for (size_t i = 0; i < size; i++) { + fossil_tofu_erase(&array[i]); + } +} + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -303,4 +802,20 @@ FOSSIL_TEST_GROUP(c_generic_tofu_tests) { // Verification checks fixture ADD_TEST(test_fossil_verification_checks); ADD_TEST(test_fossil_tofu_create_invalid); + + // Benchmarking cases + ADD_TEST(benchmark_tofu_speed_create); + ADD_TEST(benchmark_tofu_speed_equals); + ADD_TEST(benchmark_tofu_speed_copy); + ADD_TEST(benchmark_tofu_speed_transform); + ADD_TEST(benchmark_tofu_speed_accumulate); + ADD_TEST(benchmark_tofu_speed_filter); + ADD_TEST(benchmark_tofu_speed_reverse); + ADD_TEST(benchmark_tofu_speed_swap); + ADD_TEST(benchmark_tofu_speed_reduce); + ADD_TEST(benchmark_tofu_speed_average); + ADD_TEST(benchmark_tofu_speed_shuffle); + ADD_TEST(benchmark_tofu_speed_for_each); + ADD_TEST(benchmark_tofu_speed_partition); + ADD_TEST(benchmark_tofu_speed_summary); } // end of tests diff --git a/code/tests/test_vector.c b/code/tests/test_vector.c index e3359bf..3c799ac 100644 --- a/code/tests/test_vector.c +++ b/code/tests/test_vector.c @@ -12,6 +12,7 @@ * ----------------------------------------------------------------------------- */ #include +#include #include #include "fossil/tofu/framework.h" @@ -88,6 +89,154 @@ FOSSIL_TEST(test_vector_search) { fossil_tofu_erase(&element3); } +FOSSIL_TEST(test_vector_reverse) { + // Push back some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_vector_push_back(mock_vector, element1); + fossil_vector_push_back(mock_vector, element2); + fossil_vector_push_back(mock_vector, element3); + + // Reverse the vector + fossil_vector_reverse(mock_vector); + + // Check if the elements are reversed + ASSUME_ITS_EQUAL_I32(5, mock_vector->data[0].value.int_val); + ASSUME_ITS_EQUAL_I32(10, mock_vector->data[1].value.int_val); + ASSUME_ITS_EQUAL_I32(42, mock_vector->data[2].value.int_val); + + fossil_tofu_erase(&element1); + fossil_tofu_erase(&element2); + fossil_tofu_erase(&element3); +} + +FOSSIL_TEST(test_vector_size) { + // Push back some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_vector_push_back(mock_vector, element1); + fossil_vector_push_back(mock_vector, element2); + fossil_vector_push_back(mock_vector, element3); + + // Check the size of the vector + ASSUME_ITS_EQUAL_U32(3, fossil_vector_size(mock_vector)); + + fossil_tofu_erase(&element1); + fossil_tofu_erase(&element2); + fossil_tofu_erase(&element3); +} + +// benchmarking cases to capture the true +// performence based on current structures +// implmentation. + +FOSSIL_TEST(benchmark_vector_push_back) { + // Push back some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + // Start the benchmark + MARK_START(vector_push_back); + + for (size_t i = 0; i < 1000000; i++) { + fossil_vector_push_back(mock_vector, element1); + fossil_vector_push_back(mock_vector, element2); + fossil_vector_push_back(mock_vector, element3); + } + + // Stop the benchmark + MARK_STOP(vector_push_back); + + // Check if the elements are added correctly + ASSUME_ITS_EQUAL_U32(3000000, mock_vector->size); + + fossil_tofu_erase(&element1); + fossil_tofu_erase(&element2); + fossil_tofu_erase(&element3); +} + +FOSSIL_TEST(benchmark_vector_search) { + // Push back some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_vector_push_back(mock_vector, element1); + fossil_vector_push_back(mock_vector, element2); + fossil_vector_push_back(mock_vector, element3); + + // Start the benchmark + MARK_START(vector_search); + + for (size_t i = 0; i < 1000000; i++) { + fossil_vector_search(mock_vector, element1); + fossil_vector_search(mock_vector, element2); + fossil_vector_search(mock_vector, element3); + } + + // Stop the benchmark + MARK_STOP(vector_search); + + fossil_tofu_erase(&element1); + fossil_tofu_erase(&element2); + fossil_tofu_erase(&element3); +} + +FOSSIL_TEST(benchmark_vector_reverse) { + // Push back some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_vector_push_back(mock_vector, element1); + fossil_vector_push_back(mock_vector, element2); + fossil_vector_push_back(mock_vector, element3); + + // Start the benchmark + MARK_START(vector_reverse); + + for (size_t i = 0; i < 1000000; i++) { + fossil_vector_reverse(mock_vector); + } + + // Stop the benchmark + MARK_STOP(vector_reverse); + + fossil_tofu_erase(&element1); + fossil_tofu_erase(&element2); + fossil_tofu_erase(&element3); +} + +FOSSIL_TEST(benchmark_vector_size) { + // Push back some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_vector_push_back(mock_vector, element1); + fossil_vector_push_back(mock_vector, element2); + fossil_vector_push_back(mock_vector, element3); + + // Start the benchmark + MARK_START(vector_size); + + for (size_t i = 0; i < 1000000; i++) { + fossil_vector_size(mock_vector); + } + + // Stop the benchmark + MARK_STOP(vector_size); + + fossil_tofu_erase(&element1); + fossil_tofu_erase(&element2); + fossil_tofu_erase(&element3); +} + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -96,4 +245,12 @@ FOSSIL_TEST_GROUP(c_vector_structure_tests) { // Vector Fixture ADD_TESTF(test_vector_push_back, struct_vect_fixture); ADD_TESTF(test_vector_search, struct_vect_fixture); + ADD_TESTF(test_vector_reverse, struct_vect_fixture); + ADD_TESTF(test_vector_size, struct_vect_fixture); + + // Vector Benchmark + ADD_TESTF(benchmark_vector_push_back, struct_vect_fixture); + ADD_TESTF(benchmark_vector_search, struct_vect_fixture); + ADD_TESTF(benchmark_vector_reverse, struct_vect_fixture); + ADD_TESTF(benchmark_vector_size, struct_vect_fixture); } // end of tests From 7ba11e715bc567dc0a0ba593a011da8dbfa99033 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Fri, 11 Oct 2024 11:17:25 -0600 Subject: [PATCH 02/10] use correct benchmark tool kit --- code/tests/test_arrayof.c | 20 ++++----- code/tests/test_doublylist.c | 16 ++++---- code/tests/test_dqueue.c | 20 ++++----- code/tests/test_forwardlist.c | 16 ++++---- code/tests/test_mapof.c | 20 ++++----- code/tests/test_pqueue.c | 20 ++++----- code/tests/test_queue.c | 16 ++++---- code/tests/test_setof.c | 16 ++++---- code/tests/test_stack.c | 12 +++--- code/tests/test_tofu.c | 76 +++++++++++++++++------------------ code/tests/test_vector.c | 16 ++++---- 11 files changed, 124 insertions(+), 124 deletions(-) diff --git a/code/tests/test_arrayof.c b/code/tests/test_arrayof.c index bb15b3a..16d378e 100644 --- a/code/tests/test_arrayof.c +++ b/code/tests/test_arrayof.c @@ -87,16 +87,16 @@ FOSSIL_TEST(test_fossil_tofu_arrayof_clear) { // implmentation. FOSSIL_TEST(benchmark_fossil_tofu_arrayof_create) { - MARK_START(fossil_tofu_arrayof_create); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 3, "10", "20", "30"); fossil_tofu_arrayof_erase(&array); } - MARK_STOP(fossil_tofu_arrayof_create); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } FOSSIL_TEST(benchmark_fossil_tofu_arrayof_add) { - MARK_START(fossil_tofu_arrayof_add); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 0); fossil_tofu_t tofu1 = fossil_tofu_create("int", "10"); @@ -105,17 +105,17 @@ FOSSIL_TEST(benchmark_fossil_tofu_arrayof_add) { fossil_tofu_arrayof_add(&array, tofu2); fossil_tofu_arrayof_erase(&array); } - MARK_STOP(fossil_tofu_arrayof_add); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } FOSSIL_TEST(benchmark_fossil_tofu_arrayof_get) { - MARK_START(fossil_tofu_arrayof_get); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 3, "10", "20", "30"); fossil_tofu_t tofu = fossil_tofu_arrayof_get(&array, 1); fossil_tofu_arrayof_erase(&array); } - MARK_STOP(fossil_tofu_arrayof_get); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } FOSSIL_TEST(benchmark_fossil_tofu_arrayof_size) { @@ -129,23 +129,23 @@ FOSSIL_TEST(benchmark_fossil_tofu_arrayof_size) { } FOSSIL_TEST(benchmark_fossil_tofu_arrayof_is_empty) { - MARK_START(fossil_tofu_arrayof_is_empty); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 0); fossil_tofu_arrayof_is_empty(&array); fossil_tofu_arrayof_erase(&array); } - MARK_STOP(fossil_tofu_arrayof_is_empty); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } FOSSIL_TEST(benchmark_fossil_tofu_arrayof_clear) { - MARK_START(fossil_tofu_arrayof_clear); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 3, "10", "20", "30"); fossil_tofu_arrayof_clear(&array); fossil_tofu_arrayof_erase(&array); } - MARK_STOP(fossil_tofu_arrayof_clear); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } // * * * * * * * * * * * * * * * * * * * * * * * * diff --git a/code/tests/test_doublylist.c b/code/tests/test_doublylist.c index d5310cb..d305c64 100644 --- a/code/tests/test_doublylist.c +++ b/code/tests/test_doublylist.c @@ -143,13 +143,13 @@ FOSSIL_TEST(benchmark_dlist_insert) { fossil_tofu_t element = fossil_tofu_create("int", "42"); // Start the benchmark - MARK_START(dlist_insert); + TEST_BENCHMARK(); // Insert the element fossil_dlist_insert(mock_dlist, element); // Stop the benchmark - MARK_STOP(dlist_insert); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -162,14 +162,14 @@ FOSSIL_TEST(benchmark_dlist_remove) { fossil_dlist_insert(mock_dlist, element); // Start the benchmark - MARK_START(dlist_remove); + TEST_BENCHMARK(); // Remove the element fossil_tofu_t removedElement; fossil_dlist_remove(mock_dlist, &removedElement); // Stop the benchmark - MARK_STOP(dlist_remove); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -185,13 +185,13 @@ FOSSIL_TEST(benchmark_dlist_reverse_forward) { fossil_dlist_insert(mock_dlist, element3); // Start the benchmark - MARK_START(dlist_reverse_forward); + TEST_BENCHMARK(); // Reverse the doubly linked list forward fossil_dlist_reverse_forward(mock_dlist); // Stop the benchmark - MARK_STOP(dlist_reverse_forward); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element1); fossil_tofu_erase(&element2); @@ -209,13 +209,13 @@ FOSSIL_TEST(benchmark_dlist_reverse_backward) { fossil_dlist_insert(mock_dlist, element3); // Start the benchmark - MARK_START(dlist_reverse_backward); + TEST_BENCHMARK(); // Reverse the doubly linked list backward fossil_dlist_reverse_backward(mock_dlist); // Stop the benchmark - MARK_STOP(dlist_reverse_backward); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element1); fossil_tofu_erase(&element2); diff --git a/code/tests/test_dqueue.c b/code/tests/test_dqueue.c index 7b6e9fb..814bbbb 100644 --- a/code/tests/test_dqueue.c +++ b/code/tests/test_dqueue.c @@ -136,13 +136,13 @@ FOSSIL_TEST(benchmark_dqueue_insert) { fossil_tofu_t element = fossil_tofu_create("int", "42"); // Start the benchmark - MARK_START(dqueue_insert); + TEST_BENCHMARK(); // Insert the element fossil_dqueue_insert(mock_dqueue, element); // Stop the benchmark - MARK_STOP(dqueue_insert); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -155,14 +155,14 @@ FOSSIL_TEST(benchmark_dqueue_remove) { fossil_dqueue_insert(mock_dqueue, element); // Start the benchmark - MARK_START(dqueue_remove); + TEST_BENCHMARK(); // Remove the element fossil_tofu_t removedElement; fossil_dqueue_remove(mock_dqueue, &removedElement); // Stop the benchmark - MARK_STOP(dqueue_remove); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -175,13 +175,13 @@ FOSSIL_TEST(benchmark_dqueue_size) { fossil_dqueue_insert(mock_dqueue, element); // Start the benchmark - MARK_START(dqueue_size); + TEST_BENCHMARK(); // Get the size fossil_dqueue_size(mock_dqueue); // Stop the benchmark - MARK_STOP(dqueue_size); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -194,14 +194,14 @@ FOSSIL_TEST(benchmark_dqueue_not_empty) { fossil_dqueue_insert(mock_dqueue, element); // Start the benchmark - MARK_START(dqueue_not_empty); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_dqueue_not_empty(mock_dqueue); } // Stop the benchmark - MARK_STOP(dqueue_not_empty); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -214,14 +214,14 @@ FOSSIL_TEST(benchmark_dqueue_is_empty) { fossil_dqueue_insert(mock_dqueue, element); // Start the benchmark - MARK_START(dqueue_is_empty); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_dqueue_is_empty(mock_dqueue); } // Stop the benchmark - MARK_STOP(dqueue_is_empty); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } diff --git a/code/tests/test_forwardlist.c b/code/tests/test_forwardlist.c index ed0f777..6d9b1d7 100644 --- a/code/tests/test_forwardlist.c +++ b/code/tests/test_forwardlist.c @@ -146,13 +146,13 @@ FOSSIL_TEST(benchmark_flist_insert) { fossil_tofu_t element = fossil_tofu_create("int", "42"); // Start the benchmark - MARK_START(flist_insert); + TEST_BENCHMARK(); // Insert the element fossil_flist_insert(mock_flist, element); // Stop the benchmark - MARK_STOP(flist_insert); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -165,14 +165,14 @@ FOSSIL_TEST(benchmark_flist_remove) { fossil_flist_insert(mock_flist, element); // Start the benchmark - MARK_START(flist_remove); + TEST_BENCHMARK(); // Remove the element fossil_tofu_t removedElement; fossil_flist_remove(mock_flist, &removedElement); // Stop the benchmark - MARK_STOP(flist_remove); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -188,13 +188,13 @@ FOSSIL_TEST(benchmark_flist_reverse_forward) { fossil_flist_insert(mock_flist, element3); // Start the benchmark - MARK_START(flist_reverse_forward); + TEST_BENCHMARK(); // Reverse the linked list forward fossil_flist_reverse_forward(mock_flist); // Stop the benchmark - MARK_STOP(flist_reverse_forward); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element1); fossil_tofu_erase(&element2); @@ -212,13 +212,13 @@ FOSSIL_TEST(benchmark_flist_reverse_backward) { fossil_flist_insert(mock_flist, element3); // Start the benchmark - MARK_START(flist_reverse_backward); + TEST_BENCHMARK(); // Reverse the linked list backward fossil_flist_reverse_backward(mock_flist); // Stop the benchmark - MARK_STOP(flist_reverse_backward); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element1); fossil_tofu_erase(&element2); diff --git a/code/tests/test_mapof.c b/code/tests/test_mapof.c index 686e264..95c415c 100644 --- a/code/tests/test_mapof.c +++ b/code/tests/test_mapof.c @@ -107,16 +107,16 @@ FOSSIL_TEST(test_fossil_tofu_mapof_clear) { // implmentation. FOSSIL_TEST(benchmark_fossil_tofu_mapof_create) { - MARK_START(fossil_tofu_mapof_create); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); fossil_tofu_mapof_erase(&map); } - MARK_STOP(fossil_tofu_mapof_create); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } FOSSIL_TEST(benchmark_fossil_tofu_mapof_add_and_get) { - MARK_START(fossil_tofu_mapof_add_and_get); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); fossil_tofu_t key = fossil_tofu_create("int", "1"); @@ -125,11 +125,11 @@ FOSSIL_TEST(benchmark_fossil_tofu_mapof_add_and_get) { fossil_tofu_t retrieved = fossil_tofu_mapof_get(&map, key); fossil_tofu_mapof_erase(&map); } - MARK_STOP(fossil_tofu_mapof_add_and_get); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } FOSSIL_TEST(benchmark_fossil_tofu_mapof_contains) { - MARK_START(fossil_tofu_mapof_contains); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); fossil_tofu_t key = fossil_tofu_create("int", "1"); @@ -138,11 +138,11 @@ FOSSIL_TEST(benchmark_fossil_tofu_mapof_contains) { fossil_tofu_mapof_contains(&map, key); fossil_tofu_mapof_erase(&map); } - MARK_STOP(fossil_tofu_mapof_contains); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } FOSSIL_TEST(benchmark_fossil_tofu_mapof_remove) { - MARK_START(fossil_tofu_mapof_remove); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); fossil_tofu_t key = fossil_tofu_create("int", "1"); @@ -151,11 +151,11 @@ FOSSIL_TEST(benchmark_fossil_tofu_mapof_remove) { fossil_tofu_mapof_remove(&map, key); fossil_tofu_mapof_erase(&map); } - MARK_STOP(fossil_tofu_mapof_remove); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } FOSSIL_TEST(benchmark_fossil_tofu_mapof_size) { - MARK_START(fossil_tofu_mapof_size); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); fossil_tofu_t key1 = fossil_tofu_create("int", "1"); @@ -167,7 +167,7 @@ FOSSIL_TEST(benchmark_fossil_tofu_mapof_size) { fossil_tofu_mapof_size(&map); fossil_tofu_mapof_erase(&map); } - MARK_STOP(fossil_tofu_mapof_size); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } // * * * * * * * * * * * * * * * * * * * * * * * * diff --git a/code/tests/test_pqueue.c b/code/tests/test_pqueue.c index c8b98c6..3869d79 100644 --- a/code/tests/test_pqueue.c +++ b/code/tests/test_pqueue.c @@ -106,14 +106,14 @@ FOSSIL_TEST(benchmark_pqueue_insert) { fossil_tofu_t element = fossil_tofu_create("int", "42"); // Start the benchmark - MARK_START(pqueue_insert); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_pqueue_insert(mock_pqueue, element, 2); } // Stop the benchmark - MARK_STOP(pqueue_insert); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -126,14 +126,14 @@ FOSSIL_TEST(benchmark_pqueue_remove) { fossil_pqueue_insert(mock_pqueue, element, 2); // Start the benchmark - MARK_START(pqueue_remove); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_pqueue_remove(mock_pqueue, &element, 0); } // Stop the benchmark - MARK_STOP(pqueue_remove); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -146,14 +146,14 @@ FOSSIL_TEST(benchmark_pqueue_size) { fossil_pqueue_insert(mock_pqueue, element, 2); // Start the benchmark - MARK_START(pqueue_size); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_pqueue_size(mock_pqueue); } // Stop the benchmark - MARK_STOP(pqueue_size); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -166,14 +166,14 @@ FOSSIL_TEST(benchmark_pqueue_not_empty) { fossil_pqueue_insert(mock_pqueue, element, 2); // Start the benchmark - MARK_START(pqueue_not_empty); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_pqueue_not_empty(mock_pqueue); } // Stop the benchmark - MARK_STOP(pqueue_not_empty); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -186,14 +186,14 @@ FOSSIL_TEST(benchmark_pqueue_is_empty) { fossil_pqueue_insert(mock_pqueue, element, 2); // Start the benchmark - MARK_START(pqueue_is_empty); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_pqueue_is_empty(mock_pqueue); } // Stop the benchmark - MARK_STOP(pqueue_is_empty); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } diff --git a/code/tests/test_queue.c b/code/tests/test_queue.c index ade88e4..2da2a6d 100644 --- a/code/tests/test_queue.c +++ b/code/tests/test_queue.c @@ -114,14 +114,14 @@ FOSSIL_TEST(benchmark_queue_insert) { fossil_tofu_t element = fossil_tofu_create("int", "42"); // Start the benchmark - MARK_START(queue_insert); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_queue_insert(mock_queue, element); } // Stop the benchmark - MARK_STOP(queue_insert); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -134,14 +134,14 @@ FOSSIL_TEST(benchmark_queue_remove) { fossil_queue_insert(mock_queue, element); // Start the benchmark - MARK_START(queue_remove); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_queue_remove(mock_queue, &element); } // Stop the benchmark - MARK_STOP(queue_remove); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -154,14 +154,14 @@ FOSSIL_TEST(benchmark_queue_size) { fossil_queue_insert(mock_queue, element); // Start the benchmark - MARK_START(queue_size); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_queue_size(mock_queue); } // Stop the benchmark - MARK_STOP(queue_size); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -174,14 +174,14 @@ FOSSIL_TEST(benchmark_queue_not_empty) { fossil_queue_insert(mock_queue, element); // Start the benchmark - MARK_START(queue_not_empty); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_queue_not_empty(mock_queue); } // Stop the benchmark - MARK_STOP(queue_not_empty); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } diff --git a/code/tests/test_setof.c b/code/tests/test_setof.c index b406911..9d547e9 100644 --- a/code/tests/test_setof.c +++ b/code/tests/test_setof.c @@ -117,14 +117,14 @@ FOSSIL_TEST(benchmark_set_insert) { fossil_tofu_t element = fossil_tofu_create("int", "42"); // Start the benchmark - MARK_START(set_insert); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_set_insert(mock_set, element); } // Stop the benchmark - MARK_STOP(set_insert); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -137,14 +137,14 @@ FOSSIL_TEST(benchmark_set_remove) { fossil_set_insert(mock_set, element); // Start the benchmark - MARK_START(set_remove); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_set_remove(mock_set, element); } // Stop the benchmark - MARK_STOP(set_remove); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -157,14 +157,14 @@ FOSSIL_TEST(benchmark_set_size) { fossil_set_insert(mock_set, element); // Start the benchmark - MARK_START(set_size); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_set_size(mock_set); } // Stop the benchmark - MARK_STOP(set_size); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -177,14 +177,14 @@ FOSSIL_TEST(benchmark_set_contains) { fossil_set_insert(mock_set, element); // Start the benchmark - MARK_START(set_contains); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_set_contains(mock_set, element); } // Stop the benchmark - MARK_STOP(set_contains); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } diff --git a/code/tests/test_stack.c b/code/tests/test_stack.c index 7fdc3a0..ecf6292 100644 --- a/code/tests/test_stack.c +++ b/code/tests/test_stack.c @@ -101,14 +101,14 @@ FOSSIL_TEST(benchmark_stack_insert) { fossil_tofu_t element = fossil_tofu_create("int", "42"); // Start the benchmark - MARK_START(stack_insert); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_stack_insert(mock_stack, element); } // Stop the benchmark - MARK_STOP(stack_insert); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -121,14 +121,14 @@ FOSSIL_TEST(benchmark_stack_remove) { fossil_stack_insert(mock_stack, element); // Start the benchmark - MARK_START(stack_remove); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_stack_remove(mock_stack, &element); } // Stop the benchmark - MARK_STOP(stack_remove); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } @@ -141,14 +141,14 @@ FOSSIL_TEST(benchmark_stack_size) { fossil_stack_insert(mock_stack, element); // Start the benchmark - MARK_START(stack_size); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_stack_size(mock_stack); } // Stop the benchmark - MARK_STOP(stack_size); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element); } diff --git a/code/tests/test_tofu.c b/code/tests/test_tofu.c index 73e1225..931a385 100644 --- a/code/tests/test_tofu.c +++ b/code/tests/test_tofu.c @@ -284,12 +284,12 @@ FOSSIL_TEST(test_fossil_tofu_create_invalid) { FOSSIL_TEST(benchmark_tofu_speed_create) { // Start the benchmark - MARK_START(tofu_speed_create); + TEST_BENCHMARK(); fossil_tofu_t tofu = fossil_tofu_create("int", "100"); // Stop the benchmark - MARK_STOP(tofu_speed_create); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&tofu); @@ -301,13 +301,13 @@ FOSSIL_TEST(benchmark_tofu_speed_equals) { fossil_tofu_t tofu2 = fossil_tofu_create("int", "100"); // Start the benchmark - MARK_START(tofu_speed_equals); + TEST_BENCHMARK(); // Compare the two tofu objects fossil_tofu_equals(tofu1, tofu2); // Stop the benchmark - MARK_STOP(tofu_speed_equals); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&tofu1); fossil_tofu_erase(&tofu2); @@ -318,13 +318,13 @@ FOSSIL_TEST(benchmark_tofu_speed_copy) { fossil_tofu_t tofu_orig = fossil_tofu_create("int", "100"); // Start the benchmark - MARK_START(tofu_speed_copy); + TEST_BENCHMARK(); // Copy the tofu object fossil_tofu_t tofu_copy = fossil_tofu_copy(tofu_orig); // Stop the benchmark - MARK_STOP(tofu_speed_copy); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&tofu_orig); fossil_tofu_erase(&tofu_copy); @@ -340,13 +340,13 @@ FOSSIL_TEST(benchmark_tofu_speed_transform) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_transform); + TEST_BENCHMARK(); // Transform the array fossil_tofu_actionof_transform(array, size, double_value); // Stop the benchmark - MARK_STOP(tofu_speed_transform); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -367,13 +367,13 @@ FOSSIL_TEST(benchmark_tofu_speed_accumulate) { fossil_tofu_t init = fossil_tofu_create("int", "0"); // Start the benchmark - MARK_START(tofu_speed_accumulate); + TEST_BENCHMARK(); // Accumulate the array fossil_tofu_actionof_accumulate(array, size, init, sum); // Stop the benchmark - MARK_STOP(tofu_speed_accumulate); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -392,13 +392,13 @@ FOSSIL_TEST(benchmark_tofu_speed_filter) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_filter); + TEST_BENCHMARK(); // Filter the array fossil_tofu_actionof_filter(array, size, tofu_mock_is_even); // Stop the benchmark - MARK_STOP(tofu_speed_filter); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -416,13 +416,13 @@ FOSSIL_TEST(benchmark_tofu_speed_reverse) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_reverse); + TEST_BENCHMARK(); // Reverse the array fossil_tofu_actionof_reverse(array, size); // Stop the benchmark - MARK_STOP(tofu_speed_reverse); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -439,13 +439,13 @@ FOSSIL_TEST(benchmark_tofu_speed_swap) { }; // Start the benchmark - MARK_START(tofu_speed_swap); + TEST_BENCHMARK(); // Swap two tofu objects fossil_tofu_actionof_swap(array, 0, 2); // Stop the benchmark - MARK_STOP(tofu_speed_swap); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < 3; i++) { @@ -463,13 +463,13 @@ FOSSIL_TEST(benchmark_tofu_speed_reduce) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_reduce); + TEST_BENCHMARK(); // Reduce the array fossil_tofu_actionof_reduce(array, size, sum_function); // Stop the benchmark - MARK_STOP(tofu_speed_reduce); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -488,13 +488,13 @@ FOSSIL_TEST(benchmark_tofu_speed_average) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_average); + TEST_BENCHMARK(); // Calculate the average of the array fossil_tofu_actionof_average(array, size); // Stop the benchmark - MARK_STOP(tofu_speed_average); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -513,13 +513,13 @@ FOSSIL_TEST(benchmark_tofu_speed_shuffle) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_shuffle); + TEST_BENCHMARK(); // Shuffle the array fossil_tofu_actionof_shuffle(array, size); // Stop the benchmark - MARK_STOP(tofu_speed_shuffle); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -538,13 +538,13 @@ FOSSIL_TEST(benchmark_tofu_speed_for_each) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_for_each); + TEST_BENCHMARK(); // Apply a function to each element in the array fossil_tofu_actionof_for_each(array, size, double_value); // Stop the benchmark - MARK_STOP(tofu_speed_for_each); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -570,13 +570,13 @@ FOSSIL_TEST(benchmark_tofu_speed_partition) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_partition); + TEST_BENCHMARK(); // Partition the array fossil_tofu_actionof_partition(array, size, tofu_mock_is_even); // Stop the benchmark - MARK_STOP(tofu_speed_partition); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -602,13 +602,13 @@ FOSSIL_TEST(benchmark_tofu_speed_summary) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_summary); + TEST_BENCHMARK(); // Calculate the summary of the array fossil_tofu_actionof_summary(array, size, sum_function); // Stop the benchmark - MARK_STOP(tofu_speed_summary); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -634,13 +634,13 @@ FOSSIL_TEST(benchmark_tofu_speed_average) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_average); + TEST_BENCHMARK(); // Calculate the average of the array fossil_tofu_actionof_average(array, size); // Stop the benchmark - MARK_STOP(tofu_speed_average); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -666,13 +666,13 @@ FOSSIL_TEST(benchmark_tofu_speed_shuffle) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_shuffle); + TEST_BENCHMARK(); // Shuffle the array fossil_tofu_actionof_shuffle(array, size); // Stop the benchmark - MARK_STOP(tofu_speed_shuffle); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -698,13 +698,13 @@ FOSSIL_TEST(benchmark_tofu_speed_for_each) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_for_each); + TEST_BENCHMARK(); // Apply a function to each element in the array fossil_tofu_actionof_for_each(array, size, double_value); // Stop the benchmark - MARK_STOP(tofu_speed_for_each); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -730,13 +730,13 @@ FOSSIL_TEST(benchmark_tofu_speed_partition) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_partition); + TEST_BENCHMARK(); // Partition the array fossil_tofu_actionof_partition(array, size, tofu_mock_is_even); // Stop the benchmark - MARK_STOP(tofu_speed_partition); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { @@ -762,13 +762,13 @@ FOSSIL_TEST(benchmark_tofu_speed_summary) { size_t size = sizeof(array) / sizeof(array[0]); // Start the benchmark - MARK_START(tofu_speed_summary); + TEST_BENCHMARK(); // Calculate the summary of the array fossil_tofu_actionof_summary(array, size, sum_function); // Stop the benchmark - MARK_STOP(tofu_speed_summary); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Erase the tofu objects for (size_t i = 0; i < size; i++) { diff --git a/code/tests/test_vector.c b/code/tests/test_vector.c index 3c799ac..82cf8a1 100644 --- a/code/tests/test_vector.c +++ b/code/tests/test_vector.c @@ -141,7 +141,7 @@ FOSSIL_TEST(benchmark_vector_push_back) { fossil_tofu_t element3 = fossil_tofu_create("int", "5"); // Start the benchmark - MARK_START(vector_push_back); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_vector_push_back(mock_vector, element1); @@ -150,7 +150,7 @@ FOSSIL_TEST(benchmark_vector_push_back) { } // Stop the benchmark - MARK_STOP(vector_push_back); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Check if the elements are added correctly ASSUME_ITS_EQUAL_U32(3000000, mock_vector->size); @@ -171,7 +171,7 @@ FOSSIL_TEST(benchmark_vector_search) { fossil_vector_push_back(mock_vector, element3); // Start the benchmark - MARK_START(vector_search); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_vector_search(mock_vector, element1); @@ -180,7 +180,7 @@ FOSSIL_TEST(benchmark_vector_search) { } // Stop the benchmark - MARK_STOP(vector_search); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element1); fossil_tofu_erase(&element2); @@ -198,14 +198,14 @@ FOSSIL_TEST(benchmark_vector_reverse) { fossil_vector_push_back(mock_vector, element3); // Start the benchmark - MARK_START(vector_reverse); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_vector_reverse(mock_vector); } // Stop the benchmark - MARK_STOP(vector_reverse); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element1); fossil_tofu_erase(&element2); @@ -223,14 +223,14 @@ FOSSIL_TEST(benchmark_vector_size) { fossil_vector_push_back(mock_vector, element3); // Start the benchmark - MARK_START(vector_size); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_vector_size(mock_vector); } // Stop the benchmark - MARK_STOP(vector_size); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); fossil_tofu_erase(&element1); fossil_tofu_erase(&element2); From 74849b35d57c7d6b03a7ba274b37f1c450d2bc01 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Fri, 11 Oct 2024 11:18:51 -0600 Subject: [PATCH 03/10] missed one --- code/tests/test_arrayof.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/tests/test_arrayof.c b/code/tests/test_arrayof.c index 16d378e..f67fad4 100644 --- a/code/tests/test_arrayof.c +++ b/code/tests/test_arrayof.c @@ -119,13 +119,13 @@ FOSSIL_TEST(benchmark_fossil_tofu_arrayof_get) { } FOSSIL_TEST(benchmark_fossil_tofu_arrayof_size) { - MARK_START(fossil_tofu_arrayof_size); + TEST_BENCHMARK(); for (size_t i = 0; i < 1000000; i++) { fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 2, "10", "20"); fossil_tofu_arrayof_size(&array); fossil_tofu_arrayof_erase(&array); } - MARK_STOP(fossil_tofu_arrayof_size); + TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } FOSSIL_TEST(benchmark_fossil_tofu_arrayof_is_empty) { From ecc2d11de21261181b6e4c8697247a31a26ad3a9 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Fri, 11 Oct 2024 11:27:07 -0600 Subject: [PATCH 04/10] make use of tofu var --- code/tests/test_arrayof.c | 1 + 1 file changed, 1 insertion(+) diff --git a/code/tests/test_arrayof.c b/code/tests/test_arrayof.c index f67fad4..f124848 100644 --- a/code/tests/test_arrayof.c +++ b/code/tests/test_arrayof.c @@ -113,6 +113,7 @@ FOSSIL_TEST(benchmark_fossil_tofu_arrayof_get) { for (size_t i = 0; i < 1000000; i++) { fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 3, "10", "20", "30"); fossil_tofu_t tofu = fossil_tofu_arrayof_get(&array, 1); + ASSUME_ITS_EQUAL_I32(20, tofu.value.int_val); fossil_tofu_arrayof_erase(&array); } TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); From 06b4f3ec63fdd9254fcc120ddde078792d328afe Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Fri, 11 Oct 2024 11:30:16 -0600 Subject: [PATCH 05/10] make use of this var --- code/tests/test_mapof.c | 1 + 1 file changed, 1 insertion(+) diff --git a/code/tests/test_mapof.c b/code/tests/test_mapof.c index 95c415c..85a34b4 100644 --- a/code/tests/test_mapof.c +++ b/code/tests/test_mapof.c @@ -123,6 +123,7 @@ FOSSIL_TEST(benchmark_fossil_tofu_mapof_add_and_get) { fossil_tofu_t value = fossil_tofu_create("int", "100"); fossil_tofu_mapof_add(&map, key, value); fossil_tofu_t retrieved = fossil_tofu_mapof_get(&map, key); + ASSUME_ITS_EQUAL_I32(100, retrieved.value.int_val); fossil_tofu_mapof_erase(&map); } TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); From fed007793add1394bc927106ba2922ba9bbb5f40 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Fri, 11 Oct 2024 11:38:40 -0600 Subject: [PATCH 06/10] remove extra cases --- code/tests/test_tofu.c | 139 ----------------------------------------- 1 file changed, 139 deletions(-) diff --git a/code/tests/test_tofu.c b/code/tests/test_tofu.c index 931a385..f6662f2 100644 --- a/code/tests/test_tofu.c +++ b/code/tests/test_tofu.c @@ -477,113 +477,6 @@ FOSSIL_TEST(benchmark_tofu_speed_reduce) { } } -// Test case for benchmarking the average function -FOSSIL_TEST(benchmark_tofu_speed_average) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "10"), - fossil_tofu_create("int", "20"), - fossil_tofu_create("int", "30") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Start the benchmark - TEST_BENCHMARK(); - - // Calculate the average of the array - fossil_tofu_actionof_average(array, size); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } -} - -// Test case for benchmarking the shuffle function -FOSSIL_TEST(benchmark_tofu_speed_shuffle) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "10"), - fossil_tofu_create("int", "20"), - fossil_tofu_create("int", "30") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Start the benchmark - TEST_BENCHMARK(); - - // Shuffle the array - fossil_tofu_actionof_shuffle(array, size); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } -} - -// Test case for benchmarking the for_each function -FOSSIL_TEST(benchmark_tofu_speed_for_each) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "10"), - fossil_tofu_create("int", "20"), - fossil_tofu_create("int", "30") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Start the benchmark - TEST_BENCHMARK(); - - // Apply a function to each element in the array - fossil_tofu_actionof_for_each(array, size, double_value); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } -} - -// Test case for benchmarking the partition function -FOSSIL_TEST(benchmark_tofu_speed_partition) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "10"), - fossil_tofu_create("int", "20"), - fossil_tofu_create("int", "30"), - fossil_tofu_create("int", "40"), - fossil_tofu_create("int", "50"), - fossil_tofu_create("int", "60"), - fossil_tofu_create("int", "70"), - fossil_tofu_create("int", "80"), - fossil_tofu_create("int", "90"), - fossil_tofu_create("int", "100") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Start the benchmark - TEST_BENCHMARK(); - - // Partition the array - fossil_tofu_actionof_partition(array, size, tofu_mock_is_even); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } -} - // Test case for benchmarking the summary function FOSSIL_TEST(benchmark_tofu_speed_summary) { // Create an array of tofu objects @@ -744,38 +637,6 @@ FOSSIL_TEST(benchmark_tofu_speed_partition) { } } -// Test case for benchmarking the summary function -FOSSIL_TEST(benchmark_tofu_speed_summary) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "1"), - fossil_tofu_create("int", "2"), - fossil_tofu_create("int", "3"), - fossil_tofu_create("int", "4"), - fossil_tofu_create("int", "5"), - fossil_tofu_create("int", "6"), - fossil_tofu_create("int", "7"), - fossil_tofu_create("int", "8"), - fossil_tofu_create("int", "9"), - fossil_tofu_create("int", "10") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Start the benchmark - TEST_BENCHMARK(); - - // Calculate the summary of the array - fossil_tofu_actionof_summary(array, size, sum_function); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } -} - // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * From eef496d74d4a3e264a95c3ef1b2c8666327d3223 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Fri, 11 Oct 2024 11:44:45 -0600 Subject: [PATCH 07/10] rm case --- code/tests/test_tofu.c | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/code/tests/test_tofu.c b/code/tests/test_tofu.c index f6662f2..c4070fa 100644 --- a/code/tests/test_tofu.c +++ b/code/tests/test_tofu.c @@ -573,38 +573,6 @@ FOSSIL_TEST(benchmark_tofu_speed_shuffle) { } } -// Test case for benchmarking the for_each function -FOSSIL_TEST(benchmark_tofu_speed_for_each) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "1"), - fossil_tofu_create("int", "2"), - fossil_tofu_create("int", "3"), - fossil_tofu_create("int", "4"), - fossil_tofu_create("int", "5"), - fossil_tofu_create("int", "6"), - fossil_tofu_create("int", "7"), - fossil_tofu_create("int", "8"), - fossil_tofu_create("int", "9"), - fossil_tofu_create("int", "10") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Start the benchmark - TEST_BENCHMARK(); - - // Apply a function to each element in the array - fossil_tofu_actionof_for_each(array, size, double_value); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } -} - // Test case for benchmarking the partition function FOSSIL_TEST(benchmark_tofu_speed_partition) { // Create an array of tofu objects @@ -676,7 +644,6 @@ FOSSIL_TEST_GROUP(c_generic_tofu_tests) { ADD_TEST(benchmark_tofu_speed_reduce); ADD_TEST(benchmark_tofu_speed_average); ADD_TEST(benchmark_tofu_speed_shuffle); - ADD_TEST(benchmark_tofu_speed_for_each); ADD_TEST(benchmark_tofu_speed_partition); ADD_TEST(benchmark_tofu_speed_summary); } // end of tests From a6c53d2fff954c0e37813d11e4dff913d5023903 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Fri, 11 Oct 2024 11:54:28 -0600 Subject: [PATCH 08/10] add benchmark --- code/tests/meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/code/tests/meson.build b/code/tests/meson.build index c3b9e87..cd22f08 100644 --- a/code/tests/meson.build +++ b/code/tests/meson.build @@ -17,6 +17,7 @@ if get_option('with_test').enabled() dependencies: [ dependency('fossil-test'), dependency('fossil-mock'), + dependency('fossil-mark'), fossil_tofu_dep]) test('Pizza Test Run', pizza) From 056522239a7224526e58fa613a63287af00f3f08 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Fri, 11 Oct 2024 12:11:43 -0600 Subject: [PATCH 09/10] use fixture --- code/tests/test_dqueue.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code/tests/test_dqueue.c b/code/tests/test_dqueue.c index 814bbbb..aabc84e 100644 --- a/code/tests/test_dqueue.c +++ b/code/tests/test_dqueue.c @@ -237,9 +237,9 @@ FOSSIL_TEST_GROUP(c_dqueue_structure_tests) { ADD_TESTF(test_dqueue_not_empty_and_is_empty, struct_dqueue_fixture); // Benchmarking cases - ADD_TEST(benchmark_dqueue_insert); - ADD_TEST(benchmark_dqueue_remove); - ADD_TEST(benchmark_dqueue_size); - ADD_TEST(benchmark_dqueue_not_empty); - ADD_TEST(benchmark_dqueue_is_empty); + ADD_TESTF(benchmark_dqueue_insert, struct_dqueue_fixture); + ADD_TESTF(benchmark_dqueue_remove, struct_dqueue_fixture); + ADD_TESTF(benchmark_dqueue_size, struct_dqueue_fixture); + ADD_TESTF(benchmark_dqueue_not_empty, struct_dqueue_fixture); + ADD_TESTF(benchmark_dqueue_is_empty, struct_dqueue_fixture); } // end of tests From 76ea032163253c4d2d4033cf382ae42ab809a174 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Fri, 11 Oct 2024 13:30:23 -0600 Subject: [PATCH 10/10] update mark test to showcase stress testing --- code/tests/test_arrayof.c | 73 +------- code/tests/test_doublylist.c | 75 +------- code/tests/test_dqueue.c | 88 +-------- code/tests/test_forwardlist.c | 81 +-------- code/tests/test_mapof.c | 67 +------ code/tests/test_pqueue.c | 89 +-------- code/tests/test_queue.c | 66 +------ code/tests/test_setof.c | 66 +------ code/tests/test_stack.c | 45 +---- code/tests/test_tofu.c | 333 +--------------------------------- code/tests/test_vector.c | 92 +--------- 11 files changed, 50 insertions(+), 1025 deletions(-) diff --git a/code/tests/test_arrayof.c b/code/tests/test_arrayof.c index f124848..78772f4 100644 --- a/code/tests/test_arrayof.c +++ b/code/tests/test_arrayof.c @@ -86,67 +86,13 @@ FOSSIL_TEST(test_fossil_tofu_arrayof_clear) { // performence based on current structures // implmentation. -FOSSIL_TEST(benchmark_fossil_tofu_arrayof_create) { - TEST_BENCHMARK(); - for (size_t i = 0; i < 1000000; i++) { - fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 3, "10", "20", "30"); - fossil_tofu_arrayof_erase(&array); - } - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -FOSSIL_TEST(benchmark_fossil_tofu_arrayof_add) { - TEST_BENCHMARK(); - for (size_t i = 0; i < 1000000; i++) { - fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 0); - fossil_tofu_t tofu1 = fossil_tofu_create("int", "10"); - fossil_tofu_t tofu2 = fossil_tofu_create("int", "20"); - fossil_tofu_arrayof_add(&array, tofu1); - fossil_tofu_arrayof_add(&array, tofu2); - fossil_tofu_arrayof_erase(&array); - } - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -FOSSIL_TEST(benchmark_fossil_tofu_arrayof_get) { - TEST_BENCHMARK(); - for (size_t i = 0; i < 1000000; i++) { - fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 3, "10", "20", "30"); - fossil_tofu_t tofu = fossil_tofu_arrayof_get(&array, 1); - ASSUME_ITS_EQUAL_I32(20, tofu.value.int_val); - fossil_tofu_arrayof_erase(&array); - } - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -FOSSIL_TEST(benchmark_fossil_tofu_arrayof_size) { - TEST_BENCHMARK(); - for (size_t i = 0; i < 1000000; i++) { - fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 2, "10", "20"); - fossil_tofu_arrayof_size(&array); - fossil_tofu_arrayof_erase(&array); - } - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -FOSSIL_TEST(benchmark_fossil_tofu_arrayof_is_empty) { - TEST_BENCHMARK(); - for (size_t i = 0; i < 1000000; i++) { - fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 0); - fossil_tofu_arrayof_is_empty(&array); - fossil_tofu_arrayof_erase(&array); - } - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -FOSSIL_TEST(benchmark_fossil_tofu_arrayof_clear) { - TEST_BENCHMARK(); - for (size_t i = 0; i < 1000000; i++) { - fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 3, "10", "20", "30"); - fossil_tofu_arrayof_clear(&array); - fossil_tofu_arrayof_erase(&array); +FOSSIL_TEST(stress_test_array) { + fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 0); + for (int i = 0; i < 1000000; i++) { + fossil_tofu_t tofu = fossil_tofu_create("int", "10"); + fossil_tofu_arrayof_add(&array, tofu); } - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); + fossil_tofu_arrayof_erase(&array); } // * * * * * * * * * * * * * * * * * * * * * * * * @@ -162,10 +108,5 @@ FOSSIL_TEST_GROUP(c_arrayof_structure_tests) { ADD_TEST(test_fossil_tofu_arrayof_clear); // Benchmarking - ADD_TEST(benchmark_fossil_tofu_arrayof_create); - ADD_TEST(benchmark_fossil_tofu_arrayof_add); - ADD_TEST(benchmark_fossil_tofu_arrayof_get); - ADD_TEST(benchmark_fossil_tofu_arrayof_size); - ADD_TEST(benchmark_fossil_tofu_arrayof_is_empty); - ADD_TEST(benchmark_fossil_tofu_arrayof_clear); + ADD_TEST(stress_test_array); } // end of tests diff --git a/code/tests/test_doublylist.c b/code/tests/test_doublylist.c index d305c64..07c2030 100644 --- a/code/tests/test_doublylist.c +++ b/code/tests/test_doublylist.c @@ -138,7 +138,7 @@ FOSSIL_TEST(test_dlist_reverse_backward) { // performence based on current structures // implmentation. -FOSSIL_TEST(benchmark_dlist_insert) { +FOSSIL_TEST(stress_test_dlist) { // Create an element fossil_tofu_t element = fossil_tofu_create("int", "42"); @@ -154,74 +154,6 @@ FOSSIL_TEST(benchmark_dlist_insert) { fossil_tofu_erase(&element); } -FOSSIL_TEST(benchmark_dlist_remove) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_dlist_insert(mock_dlist, element); - - // Start the benchmark - TEST_BENCHMARK(); - - // Remove the element - fossil_tofu_t removedElement; - fossil_dlist_remove(mock_dlist, &removedElement); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_dlist_reverse_forward) { - // Insert some elements - fossil_tofu_t element1 = fossil_tofu_create("int", "42"); - fossil_tofu_t element2 = fossil_tofu_create("int", "10"); - fossil_tofu_t element3 = fossil_tofu_create("int", "5"); - - fossil_dlist_insert(mock_dlist, element1); - fossil_dlist_insert(mock_dlist, element2); - fossil_dlist_insert(mock_dlist, element3); - - // Start the benchmark - TEST_BENCHMARK(); - - // Reverse the doubly linked list forward - fossil_dlist_reverse_forward(mock_dlist); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element1); - fossil_tofu_erase(&element2); - fossil_tofu_erase(&element3); -} - -FOSSIL_TEST(benchmark_dlist_reverse_backward) { - // Insert some elements - fossil_tofu_t element1 = fossil_tofu_create("int", "42"); - fossil_tofu_t element2 = fossil_tofu_create("int", "10"); - fossil_tofu_t element3 = fossil_tofu_create("int", "5"); - - fossil_dlist_insert(mock_dlist, element1); - fossil_dlist_insert(mock_dlist, element2); - fossil_dlist_insert(mock_dlist, element3); - - // Start the benchmark - TEST_BENCHMARK(); - - // Reverse the doubly linked list backward - fossil_dlist_reverse_backward(mock_dlist); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element1); - fossil_tofu_erase(&element2); - fossil_tofu_erase(&element3); -} - // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -233,8 +165,5 @@ FOSSIL_TEST_GROUP(c_dlist_structure_tests) { ADD_TESTF(test_dlist_reverse_forward, struct_dlist_fixture); ADD_TESTF(test_dlist_reverse_backward, struct_dlist_fixture); - ADD_TESTF(benchmark_dlist_insert, struct_dlist_fixture); - ADD_TESTF(benchmark_dlist_remove, struct_dlist_fixture); - ADD_TESTF(benchmark_dlist_reverse_forward, struct_dlist_fixture); - ADD_TESTF(benchmark_dlist_reverse_backward, struct_dlist_fixture); + ADD_TESTF(stress_test_dlist, struct_dlist_fixture); } // end of tests diff --git a/code/tests/test_dqueue.c b/code/tests/test_dqueue.c index aabc84e..e4df98b 100644 --- a/code/tests/test_dqueue.c +++ b/code/tests/test_dqueue.c @@ -131,93 +131,15 @@ FOSSIL_TEST(test_dqueue_not_empty_and_is_empty) { // performence based on current structures // implmentation. -FOSSIL_TEST(benchmark_dqueue_insert) { +FOSSIL_TEST(stress_test_dqueue) { // Create an element fossil_tofu_t element = fossil_tofu_create("int", "42"); // Start the benchmark TEST_BENCHMARK(); - // Insert the element - fossil_dqueue_insert(mock_dqueue, element); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_dqueue_remove) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_dqueue_insert(mock_dqueue, element); - - // Start the benchmark - TEST_BENCHMARK(); - - // Remove the element - fossil_tofu_t removedElement; - fossil_dqueue_remove(mock_dqueue, &removedElement); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_dqueue_size) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_dqueue_insert(mock_dqueue, element); - - // Start the benchmark - TEST_BENCHMARK(); - - // Get the size - fossil_dqueue_size(mock_dqueue); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_dqueue_not_empty) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_dqueue_insert(mock_dqueue, element); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { - fossil_dqueue_not_empty(mock_dqueue); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_dqueue_is_empty) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_dqueue_insert(mock_dqueue, element); - - // Start the benchmark - TEST_BENCHMARK(); - for (size_t i = 0; i < 1000000; i++) { - fossil_dqueue_is_empty(mock_dqueue); + fossil_dqueue_insert(mock_dqueue, element); } // Stop the benchmark @@ -237,9 +159,5 @@ FOSSIL_TEST_GROUP(c_dqueue_structure_tests) { ADD_TESTF(test_dqueue_not_empty_and_is_empty, struct_dqueue_fixture); // Benchmarking cases - ADD_TESTF(benchmark_dqueue_insert, struct_dqueue_fixture); - ADD_TESTF(benchmark_dqueue_remove, struct_dqueue_fixture); - ADD_TESTF(benchmark_dqueue_size, struct_dqueue_fixture); - ADD_TESTF(benchmark_dqueue_not_empty, struct_dqueue_fixture); - ADD_TESTF(benchmark_dqueue_is_empty, struct_dqueue_fixture); + ADD_TESTF(stress_test_dqueue, struct_dqueue_fixture); } // end of tests diff --git a/code/tests/test_forwardlist.c b/code/tests/test_forwardlist.c index 6d9b1d7..d508abd 100644 --- a/code/tests/test_forwardlist.c +++ b/code/tests/test_forwardlist.c @@ -141,15 +141,17 @@ FOSSIL_TEST(test_flist_reverse_backward) { // performence based on current structures // implmentation. -FOSSIL_TEST(benchmark_flist_insert) { +FOSSIL_TEST(stress_test_flist) { // Create an element fossil_tofu_t element = fossil_tofu_create("int", "42"); // Start the benchmark TEST_BENCHMARK(); - // Insert the element - fossil_flist_insert(mock_flist, element); + for (size_t i = 0; i < 1000000; i++) { + fossil_flist_insert(mock_flist, element); + fossil_flist_remove(mock_flist, &element); + } // Stop the benchmark TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); @@ -157,74 +159,6 @@ FOSSIL_TEST(benchmark_flist_insert) { fossil_tofu_erase(&element); } -FOSSIL_TEST(benchmark_flist_remove) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_flist_insert(mock_flist, element); - - // Start the benchmark - TEST_BENCHMARK(); - - // Remove the element - fossil_tofu_t removedElement; - fossil_flist_remove(mock_flist, &removedElement); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_flist_reverse_forward) { - // Insert some elements - fossil_tofu_t element1 = fossil_tofu_create("int", "42"); - fossil_tofu_t element2 = fossil_tofu_create("int", "10"); - fossil_tofu_t element3 = fossil_tofu_create("int", "5"); - - fossil_flist_insert(mock_flist, element1); - fossil_flist_insert(mock_flist, element2); - fossil_flist_insert(mock_flist, element3); - - // Start the benchmark - TEST_BENCHMARK(); - - // Reverse the linked list forward - fossil_flist_reverse_forward(mock_flist); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element1); - fossil_tofu_erase(&element2); - fossil_tofu_erase(&element3); -} - -FOSSIL_TEST(benchmark_flist_reverse_backward) { - // Insert some elements - fossil_tofu_t element1 = fossil_tofu_create("int", "42"); - fossil_tofu_t element2 = fossil_tofu_create("int", "10"); - fossil_tofu_t element3 = fossil_tofu_create("int", "5"); - - fossil_flist_insert(mock_flist, element1); - fossil_flist_insert(mock_flist, element2); - fossil_flist_insert(mock_flist, element3); - - // Start the benchmark - TEST_BENCHMARK(); - - // Reverse the linked list backward - fossil_flist_reverse_backward(mock_flist); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element1); - fossil_tofu_erase(&element2); - fossil_tofu_erase(&element3); -} - // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -236,8 +170,5 @@ FOSSIL_TEST_GROUP(c_flist_structure_tests) { ADD_TESTF(test_flist_reverse_backward, struct_flist_fixture); // Benchmarking cases - ADD_TEST(benchmark_flist_insert); - ADD_TEST(benchmark_flist_remove); - ADD_TEST(benchmark_flist_reverse_forward); - ADD_TEST(benchmark_flist_reverse_backward); + ADD_TESTF(stress_test_flist, struct_flist_fixture); } // end of tests diff --git a/code/tests/test_mapof.c b/code/tests/test_mapof.c index 85a34b4..6e89434 100644 --- a/code/tests/test_mapof.c +++ b/code/tests/test_mapof.c @@ -106,69 +106,26 @@ FOSSIL_TEST(test_fossil_tofu_mapof_clear) { // performence based on current structures // implmentation. -FOSSIL_TEST(benchmark_fossil_tofu_mapof_create) { - TEST_BENCHMARK(); - for (size_t i = 0; i < 1000000; i++) { - fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); - fossil_tofu_mapof_erase(&map); - } - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -FOSSIL_TEST(benchmark_fossil_tofu_mapof_add_and_get) { - TEST_BENCHMARK(); - for (size_t i = 0; i < 1000000; i++) { - fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); - fossil_tofu_t key = fossil_tofu_create("int", "1"); - fossil_tofu_t value = fossil_tofu_create("int", "100"); - fossil_tofu_mapof_add(&map, key, value); - fossil_tofu_t retrieved = fossil_tofu_mapof_get(&map, key); - ASSUME_ITS_EQUAL_I32(100, retrieved.value.int_val); - fossil_tofu_mapof_erase(&map); - } - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} +FOSSIL_TEST(stress_test_map) { + // Create a map object + fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); -FOSSIL_TEST(benchmark_fossil_tofu_mapof_contains) { + // Start the benchmark TEST_BENCHMARK(); - for (size_t i = 0; i < 1000000; i++) { - fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); - fossil_tofu_t key = fossil_tofu_create("int", "1"); - fossil_tofu_t value = fossil_tofu_create("int", "100"); - fossil_tofu_mapof_add(&map, key, value); - fossil_tofu_mapof_contains(&map, key); - fossil_tofu_mapof_erase(&map); - } - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} -FOSSIL_TEST(benchmark_fossil_tofu_mapof_remove) { - TEST_BENCHMARK(); + // Perform some operations for (size_t i = 0; i < 1000000; i++) { - fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); fossil_tofu_t key = fossil_tofu_create("int", "1"); fossil_tofu_t value = fossil_tofu_create("int", "100"); fossil_tofu_mapof_add(&map, key, value); fossil_tofu_mapof_remove(&map, key); - fossil_tofu_mapof_erase(&map); } - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} -FOSSIL_TEST(benchmark_fossil_tofu_mapof_size) { - TEST_BENCHMARK(); - for (size_t i = 0; i < 1000000; i++) { - fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int"); - fossil_tofu_t key1 = fossil_tofu_create("int", "1"); - fossil_tofu_t value1 = fossil_tofu_create("int", "100"); - fossil_tofu_t key2 = fossil_tofu_create("int", "2"); - fossil_tofu_t value2 = fossil_tofu_create("int", "200"); - fossil_tofu_mapof_add(&map, key1, value1); - fossil_tofu_mapof_add(&map, key2, value2); - fossil_tofu_mapof_size(&map); - fossil_tofu_mapof_erase(&map); - } + // Stop the benchmark TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); + + // Erase the map object + fossil_tofu_mapof_erase(&map); } // * * * * * * * * * * * * * * * * * * * * * * * * @@ -185,9 +142,5 @@ FOSSIL_TEST_GROUP(c_mapof_structure_tests) { ADD_TEST(test_fossil_tofu_mapof_clear); // Benchmarking - ADD_TEST(benchmark_fossil_tofu_mapof_create); - ADD_TEST(benchmark_fossil_tofu_mapof_add_and_get); - ADD_TEST(benchmark_fossil_tofu_mapof_contains); - ADD_TEST(benchmark_fossil_tofu_mapof_remove); - ADD_TEST(benchmark_fossil_tofu_mapof_size); + ADD_TEST(stress_test_map); } // end of tests diff --git a/code/tests/test_pqueue.c b/code/tests/test_pqueue.c index 3869d79..c24f1fb 100644 --- a/code/tests/test_pqueue.c +++ b/code/tests/test_pqueue.c @@ -101,7 +101,7 @@ FOSSIL_TEST(test_pqueue_not_empty_and_is_empty) { // performence based on current structures // implmentation. -FOSSIL_TEST(benchmark_pqueue_insert) { +FOSSIL_TEST(stress_test_pqueue) { // Create an element fossil_tofu_t element = fossil_tofu_create("int", "42"); @@ -110,86 +110,7 @@ FOSSIL_TEST(benchmark_pqueue_insert) { for (size_t i = 0; i < 1000000; i++) { fossil_pqueue_insert(mock_pqueue, element, 2); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_pqueue_remove) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_pqueue_insert(mock_pqueue, element, 2); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { - fossil_pqueue_remove(mock_pqueue, &element, 0); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_pqueue_size) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_pqueue_insert(mock_pqueue, element, 2); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { - fossil_pqueue_size(mock_pqueue); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_pqueue_not_empty) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_pqueue_insert(mock_pqueue, element, 2); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { - fossil_pqueue_not_empty(mock_pqueue); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_pqueue_is_empty) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_pqueue_insert(mock_pqueue, element, 2); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { - fossil_pqueue_is_empty(mock_pqueue); + fossil_pqueue_remove(mock_pqueue, &element, 2); } // Stop the benchmark @@ -209,9 +130,5 @@ FOSSIL_TEST_GROUP(c_pqueue_structure_tests) { ADD_TESTF(test_pqueue_not_empty_and_is_empty, struct_pqueue_fixture); // Benchmarking - ADD_TESTF(benchmark_pqueue_insert, struct_pqueue_fixture); - ADD_TESTF(benchmark_pqueue_remove, struct_pqueue_fixture); - ADD_TESTF(benchmark_pqueue_size, struct_pqueue_fixture); - ADD_TESTF(benchmark_pqueue_not_empty, struct_pqueue_fixture); - ADD_TESTF(benchmark_pqueue_is_empty, struct_pqueue_fixture); + ADD_TESTF(stress_test_pqueue, struct_pqueue_fixture); } // end of tests diff --git a/code/tests/test_queue.c b/code/tests/test_queue.c index 2da2a6d..f9678c6 100644 --- a/code/tests/test_queue.c +++ b/code/tests/test_queue.c @@ -109,7 +109,7 @@ FOSSIL_TEST(test_queue_not_empty_and_is_empty) { // performence based on current structures // implmentation. -FOSSIL_TEST(benchmark_queue_insert) { +FOSSIL_TEST(stress_test_queue) { // Create an element fossil_tofu_t element = fossil_tofu_create("int", "42"); @@ -118,25 +118,6 @@ FOSSIL_TEST(benchmark_queue_insert) { for (size_t i = 0; i < 1000000; i++) { fossil_queue_insert(mock_queue, element); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_queue_remove) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_queue_insert(mock_queue, element); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { fossil_queue_remove(mock_queue, &element); } @@ -146,46 +127,6 @@ FOSSIL_TEST(benchmark_queue_remove) { fossil_tofu_erase(&element); } -FOSSIL_TEST(benchmark_queue_size) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_queue_insert(mock_queue, element); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { - fossil_queue_size(mock_queue); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_queue_not_empty) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_queue_insert(mock_queue, element); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { - fossil_queue_not_empty(mock_queue); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -197,8 +138,5 @@ FOSSIL_TEST_GROUP(c_structure_tests) { ADD_TESTF(test_queue_not_empty_and_is_empty, struct_queue_fixture); // Benchmarking - ADD_TESTF(benchmark_queue_insert, struct_queue_fixture); - ADD_TESTF(benchmark_queue_remove, struct_queue_fixture); - ADD_TESTF(benchmark_queue_size, struct_queue_fixture); - ADD_TESTF(benchmark_queue_not_empty, struct_queue_fixture); + ADD_TESTF(stress_test_queue, struct_queue_fixture); } // end of tests diff --git a/code/tests/test_setof.c b/code/tests/test_setof.c index 9d547e9..489b006 100644 --- a/code/tests/test_setof.c +++ b/code/tests/test_setof.c @@ -112,7 +112,7 @@ FOSSIL_TEST(test_set_contains) { // performence based on current structures // implmentation. -FOSSIL_TEST(benchmark_set_insert) { +FOSSIL_TEST(stress_test_set) { // Create an element fossil_tofu_t element = fossil_tofu_create("int", "42"); @@ -121,25 +121,6 @@ FOSSIL_TEST(benchmark_set_insert) { for (size_t i = 0; i < 1000000; i++) { fossil_set_insert(mock_set, element); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_set_remove) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_set_insert(mock_set, element); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { fossil_set_remove(mock_set, element); } @@ -149,46 +130,6 @@ FOSSIL_TEST(benchmark_set_remove) { fossil_tofu_erase(&element); } -FOSSIL_TEST(benchmark_set_size) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_set_insert(mock_set, element); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { - fossil_set_size(mock_set); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_set_contains) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_set_insert(mock_set, element); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { - fossil_set_contains(mock_set, element); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -200,8 +141,5 @@ FOSSIL_TEST_GROUP(c_setof_structure_tests) { ADD_TESTF(test_set_contains, struct_set_fixture); // Benchmarking - ADD_TESTF(benchmark_set_insert, struct_set_fixture); - ADD_TESTF(benchmark_set_remove, struct_set_fixture); - ADD_TESTF(benchmark_set_size, struct_set_fixture); - ADD_TESTF(benchmark_set_contains, struct_set_fixture); + ADD_TESTF(stress_test_set, struct_set_fixture); } // end of tests diff --git a/code/tests/test_stack.c b/code/tests/test_stack.c index ecf6292..03bf339 100644 --- a/code/tests/test_stack.c +++ b/code/tests/test_stack.c @@ -96,7 +96,7 @@ FOSSIL_TEST(test_stack_remove) { // performence based on current structures // implmentation. -FOSSIL_TEST(benchmark_stack_insert) { +FOSSIL_TEST(stress_test_stack) { // Create an element fossil_tofu_t element = fossil_tofu_create("int", "42"); @@ -105,25 +105,6 @@ FOSSIL_TEST(benchmark_stack_insert) { for (size_t i = 0; i < 1000000; i++) { fossil_stack_insert(mock_stack, element); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - -FOSSIL_TEST(benchmark_stack_remove) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_stack_insert(mock_stack, element); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { fossil_stack_remove(mock_stack, &element); } @@ -133,26 +114,6 @@ FOSSIL_TEST(benchmark_stack_remove) { fossil_tofu_erase(&element); } -FOSSIL_TEST(benchmark_stack_size) { - // Create an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - - // Insert the element - fossil_stack_insert(mock_stack, element); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { - fossil_stack_size(mock_stack); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element); -} - // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -164,7 +125,5 @@ FOSSIL_TEST_GROUP(c_stack_structure_tests) { ADD_TESTF(test_stack_remove, struct_stack_fixture); // Stack Benchmark - ADD_TESTF(benchmark_stack_insert, struct_stack_fixture); - ADD_TESTF(benchmark_stack_remove, struct_stack_fixture); - ADD_TESTF(benchmark_stack_size, struct_stack_fixture); + ADD_TESTF(stress_test_stack, struct_stack_fixture); } // end of tests diff --git a/code/tests/test_tofu.c b/code/tests/test_tofu.c index c4070fa..287b84c 100644 --- a/code/tests/test_tofu.c +++ b/code/tests/test_tofu.c @@ -282,327 +282,24 @@ FOSSIL_TEST(test_fossil_tofu_create_invalid) { // performence based on current structures // implmentation. -FOSSIL_TEST(benchmark_tofu_speed_create) { - // Start the benchmark - TEST_BENCHMARK(); - - fossil_tofu_t tofu = fossil_tofu_create("int", "100"); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&tofu); - -} - -FOSSIL_TEST(benchmark_tofu_speed_equals) { - // Create two tofu objects - fossil_tofu_t tofu1 = fossil_tofu_create("int", "100"); - fossil_tofu_t tofu2 = fossil_tofu_create("int", "100"); - - // Start the benchmark - TEST_BENCHMARK(); - - // Compare the two tofu objects - fossil_tofu_equals(tofu1, tofu2); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&tofu1); - fossil_tofu_erase(&tofu2); -} - -FOSSIL_TEST(benchmark_tofu_speed_copy) { +FOSSIL_TEST(stress_test_tofu_type) { // Create a tofu object - fossil_tofu_t tofu_orig = fossil_tofu_create("int", "100"); - - // Start the benchmark - TEST_BENCHMARK(); - - // Copy the tofu object - fossil_tofu_t tofu_copy = fossil_tofu_copy(tofu_orig); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&tofu_orig); - fossil_tofu_erase(&tofu_copy); -} - -FOSSIL_TEST(benchmark_tofu_speed_transform) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "10"), - fossil_tofu_create("int", "20"), - fossil_tofu_create("int", "30") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Start the benchmark - TEST_BENCHMARK(); - - // Transform the array - fossil_tofu_actionof_transform(array, size, double_value); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } -} - -FOSSIL_TEST(benchmark_tofu_speed_accumulate) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "10"), - fossil_tofu_create("int", "20"), - fossil_tofu_create("int", "30") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Create an initial tofu object - fossil_tofu_t init = fossil_tofu_create("int", "0"); - - // Start the benchmark - TEST_BENCHMARK(); - - // Accumulate the array - fossil_tofu_actionof_accumulate(array, size, init, sum); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } - fossil_tofu_erase(&init); -} - -FOSSIL_TEST(benchmark_tofu_speed_filter) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "10"), - fossil_tofu_create("int", "20"), - fossil_tofu_create("int", "30") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Start the benchmark - TEST_BENCHMARK(); - - // Filter the array - fossil_tofu_actionof_filter(array, size, tofu_mock_is_even); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } -} - -FOSSIL_TEST(benchmark_tofu_speed_reverse) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "10"), - fossil_tofu_create("int", "20"), - fossil_tofu_create("int", "30") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Start the benchmark - TEST_BENCHMARK(); - - // Reverse the array - fossil_tofu_actionof_reverse(array, size); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } -} - -FOSSIL_TEST(benchmark_tofu_speed_swap) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "10"), - fossil_tofu_create("int", "20"), - fossil_tofu_create("int", "30") - }; - - // Start the benchmark - TEST_BENCHMARK(); - - // Swap two tofu objects - fossil_tofu_actionof_swap(array, 0, 2); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < 3; i++) { - fossil_tofu_erase(&array[i]); - } -} - -FOSSIL_TEST(benchmark_tofu_speed_reduce) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "10"), - fossil_tofu_create("int", "20"), - fossil_tofu_create("int", "30") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Start the benchmark - TEST_BENCHMARK(); - - // Reduce the array - fossil_tofu_actionof_reduce(array, size, sum_function); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } -} - -// Test case for benchmarking the summary function -FOSSIL_TEST(benchmark_tofu_speed_summary) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "10"), - fossil_tofu_create("int", "20"), - fossil_tofu_create("int", "30"), - fossil_tofu_create("int", "40"), - fossil_tofu_create("int", "50"), - fossil_tofu_create("int", "60"), - fossil_tofu_create("int", "70"), - fossil_tofu_create("int", "80"), - fossil_tofu_create("int", "90"), - fossil_tofu_create("int", "100") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Start the benchmark - TEST_BENCHMARK(); - - // Calculate the summary of the array - fossil_tofu_actionof_summary(array, size, sum_function); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } -} - -// Test case for benchmarking the average function -FOSSIL_TEST(benchmark_tofu_speed_average) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "10"), - fossil_tofu_create("int", "20"), - fossil_tofu_create("int", "30"), - fossil_tofu_create("int", "40"), - fossil_tofu_create("int", "50"), - fossil_tofu_create("int", "60"), - fossil_tofu_create("int", "70"), - fossil_tofu_create("int", "80"), - fossil_tofu_create("int", "90"), - fossil_tofu_create("int", "100") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Start the benchmark - TEST_BENCHMARK(); - - // Calculate the average of the array - fossil_tofu_actionof_average(array, size); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } -} - -// Test case for benchmarking the shuffle function -FOSSIL_TEST(benchmark_tofu_speed_shuffle) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "1"), - fossil_tofu_create("int", "2"), - fossil_tofu_create("int", "3"), - fossil_tofu_create("int", "4"), - fossil_tofu_create("int", "5"), - fossil_tofu_create("int", "6"), - fossil_tofu_create("int", "7"), - fossil_tofu_create("int", "8"), - fossil_tofu_create("int", "9"), - fossil_tofu_create("int", "10") - }; - size_t size = sizeof(array) / sizeof(array[0]); + fossil_tofu_t tofu = fossil_tofu_create("int", "100"); // Start the benchmark TEST_BENCHMARK(); - // Shuffle the array - fossil_tofu_actionof_shuffle(array, size); - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); + // Perform some operations + for (size_t i = 0; i < 1000000; i++) { + fossil_tofu_t tofu_copy = fossil_tofu_copy(tofu); + fossil_tofu_erase(&tofu_copy); } -} - -// Test case for benchmarking the partition function -FOSSIL_TEST(benchmark_tofu_speed_partition) { - // Create an array of tofu objects - fossil_tofu_t array[] = { - fossil_tofu_create("int", "1"), - fossil_tofu_create("int", "2"), - fossil_tofu_create("int", "3"), - fossil_tofu_create("int", "4"), - fossil_tofu_create("int", "5"), - fossil_tofu_create("int", "6"), - fossil_tofu_create("int", "7"), - fossil_tofu_create("int", "8"), - fossil_tofu_create("int", "9"), - fossil_tofu_create("int", "10") - }; - size_t size = sizeof(array) / sizeof(array[0]); - - // Start the benchmark - TEST_BENCHMARK(); - - // Partition the array - fossil_tofu_actionof_partition(array, size, tofu_mock_is_even); // Stop the benchmark TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - // Erase the tofu objects - for (size_t i = 0; i < size; i++) { - fossil_tofu_erase(&array[i]); - } + // Erase the tofu object + fossil_tofu_erase(&tofu); } // * * * * * * * * * * * * * * * * * * * * * * * * @@ -633,17 +330,5 @@ FOSSIL_TEST_GROUP(c_generic_tofu_tests) { ADD_TEST(test_fossil_tofu_create_invalid); // Benchmarking cases - ADD_TEST(benchmark_tofu_speed_create); - ADD_TEST(benchmark_tofu_speed_equals); - ADD_TEST(benchmark_tofu_speed_copy); - ADD_TEST(benchmark_tofu_speed_transform); - ADD_TEST(benchmark_tofu_speed_accumulate); - ADD_TEST(benchmark_tofu_speed_filter); - ADD_TEST(benchmark_tofu_speed_reverse); - ADD_TEST(benchmark_tofu_speed_swap); - ADD_TEST(benchmark_tofu_speed_reduce); - ADD_TEST(benchmark_tofu_speed_average); - ADD_TEST(benchmark_tofu_speed_shuffle); - ADD_TEST(benchmark_tofu_speed_partition); - ADD_TEST(benchmark_tofu_speed_summary); + ADD_TEST(stress_test_tofu_type); } // end of tests diff --git a/code/tests/test_vector.c b/code/tests/test_vector.c index 82cf8a1..d6b734e 100644 --- a/code/tests/test_vector.c +++ b/code/tests/test_vector.c @@ -134,8 +134,8 @@ FOSSIL_TEST(test_vector_size) { // performence based on current structures // implmentation. -FOSSIL_TEST(benchmark_vector_push_back) { - // Push back some elements +FOSSIL_TEST(stress_test_vector_usage) { + // setup nodes fossil_tofu_t element1 = fossil_tofu_create("int", "42"); fossil_tofu_t element2 = fossil_tofu_create("int", "10"); fossil_tofu_t element3 = fossil_tofu_create("int", "5"); @@ -153,88 +153,7 @@ FOSSIL_TEST(benchmark_vector_push_back) { TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); // Check if the elements are added correctly - ASSUME_ITS_EQUAL_U32(3000000, mock_vector->size); - - fossil_tofu_erase(&element1); - fossil_tofu_erase(&element2); - fossil_tofu_erase(&element3); -} - -FOSSIL_TEST(benchmark_vector_search) { - // Push back some elements - fossil_tofu_t element1 = fossil_tofu_create("int", "42"); - fossil_tofu_t element2 = fossil_tofu_create("int", "10"); - fossil_tofu_t element3 = fossil_tofu_create("int", "5"); - - fossil_vector_push_back(mock_vector, element1); - fossil_vector_push_back(mock_vector, element2); - fossil_vector_push_back(mock_vector, element3); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { - fossil_vector_search(mock_vector, element1); - fossil_vector_search(mock_vector, element2); - fossil_vector_search(mock_vector, element3); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element1); - fossil_tofu_erase(&element2); - fossil_tofu_erase(&element3); -} - -FOSSIL_TEST(benchmark_vector_reverse) { - // Push back some elements - fossil_tofu_t element1 = fossil_tofu_create("int", "42"); - fossil_tofu_t element2 = fossil_tofu_create("int", "10"); - fossil_tofu_t element3 = fossil_tofu_create("int", "5"); - - fossil_vector_push_back(mock_vector, element1); - fossil_vector_push_back(mock_vector, element2); - fossil_vector_push_back(mock_vector, element3); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { - fossil_vector_reverse(mock_vector); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element1); - fossil_tofu_erase(&element2); - fossil_tofu_erase(&element3); -} - -FOSSIL_TEST(benchmark_vector_size) { - // Push back some elements - fossil_tofu_t element1 = fossil_tofu_create("int", "42"); - fossil_tofu_t element2 = fossil_tofu_create("int", "10"); - fossil_tofu_t element3 = fossil_tofu_create("int", "5"); - - fossil_vector_push_back(mock_vector, element1); - fossil_vector_push_back(mock_vector, element2); - fossil_vector_push_back(mock_vector, element3); - - // Start the benchmark - TEST_BENCHMARK(); - - for (size_t i = 0; i < 1000000; i++) { - fossil_vector_size(mock_vector); - } - - // Stop the benchmark - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); - - fossil_tofu_erase(&element1); - fossil_tofu_erase(&element2); - fossil_tofu_erase(&element3); + ASSUME_ITS_EQUAL_I32(3000000, mock_vector->size); } // * * * * * * * * * * * * * * * * * * * * * * * * @@ -249,8 +168,5 @@ FOSSIL_TEST_GROUP(c_vector_structure_tests) { ADD_TESTF(test_vector_size, struct_vect_fixture); // Vector Benchmark - ADD_TESTF(benchmark_vector_push_back, struct_vect_fixture); - ADD_TESTF(benchmark_vector_search, struct_vect_fixture); - ADD_TESTF(benchmark_vector_reverse, struct_vect_fixture); - ADD_TESTF(benchmark_vector_size, struct_vect_fixture); + ADD_TESTF(stress_test_vector_usage, struct_vect_fixture); } // end of tests