Documentation for foreach.h, test.h, timer.h and other changes
Change in timer.h. Now cmc_timer_stop will calculate the result so goodbye cmc_timer_calc
This commit is contained in:
1 parent
aa214d179e
commit
67590790c4
12 files changed
+451
-36
No files matched your search
+134
-4
@@ -588,12 +588,23 @@ int main(void)
|
||||
<li><code>CMC_FOREACH</code> - Goes from the beginning of a Collection to the end</li>
|
||||
<li><code>CMC_FOREAC_REV</code> - Goes from the end of a Collection to the beginning</li>
|
||||
</ul>
|
||||
<h2><a class="header" href="#parameters" id="parameters">Parameters</a></h2>
|
||||
<h2><a class="header" href="#cmc_foreach" id="cmc_foreach">CMC_FOREACH</a></h2>
|
||||
<pre><code class="language-c">#define CMC_FOREACH(PFX, SNAME, ITERNAME, TARGET)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>PFX</code> - Functions prefix</li>
|
||||
<li><code>SNAME</code> - Struct name</li>
|
||||
<li><code>ITERNAME</code> - Iterator variable name</li>
|
||||
<li><code>TARGET</code> - Target variable</li>
|
||||
<li><code>TARGET</code> - Target collection variable name</li>
|
||||
</ul>
|
||||
<h2><a class="header" href="#cmc_foreach_rev" id="cmc_foreach_rev">CMC_FOREACH_REV</a></h2>
|
||||
<pre><code class="language-c">#define CMC_FOREACH_REV(PFX, SNAME, ITERNAME, TARGET)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>PFX</code> - Functions prefix</li>
|
||||
<li><code>SNAME</code> - Struct name</li>
|
||||
<li><code>ITERNAME</code> - Iterator variable name</li>
|
||||
<li><code>TARGET</code> - Target collection variable name</li>
|
||||
</ul>
|
||||
<h1><a class="header" href="#logh" id="logh">log.h</a></h1>
|
||||
<p>Simple and customizable logging macros. Messages can have a custom logging level and a custom file output. This customization can be done via the global variable <a href="utl/log.h/configuration.html#cmc_log_config"><code>cmc_log_config</code></a>. Logs are outputted to <code>stderr</code>.</p>
|
||||
@@ -732,9 +743,128 @@ int main(void)
|
||||
<li><strong>FATAL</strong> - This will probably be the last logging message before your program crashes or goes into madness. Fatal errors are commonly attributed to dereferencing NULL pointers.</li>
|
||||
</ul>
|
||||
<h1><a class="header" href="#testh" id="testh">test.h</a></h1>
|
||||
<p>Simple unit test utility.</p>
|
||||
<p>A simple <a href="https://en.wikipedia.org/wiki/Unit_testing">Unit Test</a> utility used by the C Macro Collections Library. It has two main components: a Unit and a Test.</p>
|
||||
<p>This utility uses two other libraries defined in the C Macro Collections library:</p>
|
||||
<ul>
|
||||
<li><a href="utl/test.h/../assert.h/index.html"><code>assert.h</code></a></li>
|
||||
<li><a href="utl/test.h/../timer.h/index.html"><code>timer.h</code></a></li>
|
||||
</ul>
|
||||
<p>When a test is created inside a unit, it will first set the global variable <a href="utl/test.h/../assert.h/index.html#cmc_assert_state"><code>cmc_assert_state</code></a> to <code>true</code>. Then, inside the test you can use the assertions provided by the <code>assert.h</code> library to pass or fail a unit test automatically. By the end of a test the variable will be checked. If <code>false</code> it means that a certain assertion failed.</p>
|
||||
<p>The runtime of each Unit Test is calculated using the <code>timer.h</code> library.</p>
|
||||
<h2><a class="header" href="#cmc_create_unit" id="cmc_create_unit">CMC_CREATE_UNIT</a></h2>
|
||||
<p>Creates a Unit that can contain tests.</p>
|
||||
<pre><code class="language-c">#define CMC_CREATE_UNIT(UNAME, VERBOSE, BODY)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>UNAME</code> - Unit name. This needs to be a valid function name!</li>
|
||||
<li><code>VERBOSE</code> - Either <code>true</code> or <code>false</code>. If <code>true</code>, prints every message of <code>PASSED</code> or <code>FAILED</code> from each test</li>
|
||||
<li><code>BODY</code> - A block of code containing tests</li>
|
||||
</ul>
|
||||
<h2><a class="header" href="#cmc_create_test" id="cmc_create_test">CMC_CREATE_TEST</a></h2>
|
||||
<p>Creates a test within a unit. This macro can only be used inside the <code>BODY</code> of a <code>CMC_CREATE_UNIT</code> since it uses local variables allocated by the latter.</p>
|
||||
<pre><code class="language-c">#define CMC_CREATE_TEST(TNAME, BODY)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>TNAME</code> - Test name</li>
|
||||
<li><code>BODY</code> - A block of code containing the test itself</li>
|
||||
</ul>
|
||||
<p>Inside a test you can use the assertions from <code>assert.h</code> to automatically pass or fail a test.</p>
|
||||
<h2><a class="header" href="#cmc_test_abort" id="cmc_test_abort">CMC_TEST_ABORT</a></h2>
|
||||
<p>Aborts a unit test. This will jump to a <code>goto</code> located at the end of the Unit Test.</p>
|
||||
<h2><a class="header" href="#cmc_test_info" id="cmc_test_info">cmc_test_info</a></h2>
|
||||
<p>Contains information about a Unit Test. Used internally.</p>
|
||||
<pre><code class="language-c">struct cmc_test_info
|
||||
{
|
||||
uintmax_t total;
|
||||
uintmax_t passed;
|
||||
uintmax_t failed;
|
||||
bool aborted;
|
||||
bool verbose;
|
||||
};
|
||||
</code></pre>
|
||||
<h2><a class="header" href="#cmc_test_color" id="cmc_test_color">CMC_TEST_COLOR</a></h2>
|
||||
<p>Define this macro if you wish to have color output from the messages printed by each test. Note that a Unit Test need to have <code>VERBOSE</code> equal to <code>true</code>.</p>
|
||||
<h2><a class="header" href="#example" id="example">Example</a></h2>
|
||||
<pre><code class="language-c">#include "utl/test.h"
|
||||
|
||||
CMC_CREATE_UNIT(check_math, true, {
|
||||
CMC_CREATE_TEST(summation, {
|
||||
// assert.h already comes with test.h
|
||||
cmc_assert_equals(int32_t, 4, 2 + 2);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(subtraction, {
|
||||
cmc_assert_equals(int32_t, -1, 2 - 3);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(this will fail, {
|
||||
// test names can be text as long as they don't have a comma
|
||||
cmc_assert_greater(double, 1.0, 0.0);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(fish, {
|
||||
// You can also manually fail a test
|
||||
if (strcmp("2 + 2", "fish") != 0)
|
||||
cmc_assert_state = false;
|
||||
});
|
||||
});
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// returns how many tests failed
|
||||
return check_math();
|
||||
}
|
||||
</code></pre>
|
||||
<h1><a class="header" href="#timerh" id="timerh">timer.h</a></h1>
|
||||
<p>Simple code execution utility.</p>
|
||||
<p>A very simple library that encapsulates <code>clock()</code> from <code><time.h></code>, making life easier.</p>
|
||||
<h2><a class="header" href="#cmc_timer" id="cmc_timer">cmc_timer</a></h2>
|
||||
<pre><code class="language-c">struct cmc_timer
|
||||
{
|
||||
clock_t start;
|
||||
clock_t stop;
|
||||
double result;
|
||||
};
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>clock_t start</code> - Start of timing</li>
|
||||
<li><code>clock_t stop</code> - End of timing</li>
|
||||
<li><code>double result</code> - Result in milliseconds</li>
|
||||
</ul>
|
||||
<h2><a class="header" href="#cmc_timer_start" id="cmc_timer_start">cmc_timer_start</a></h2>
|
||||
<p>Starts the timer by setting <code>start</code> with <code>clock()</code>.</p>
|
||||
<pre><code class="language-c">#define cmc_timer_start(timer)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>timer</code> - A <code>struct cmc_timer</code> variable</li>
|
||||
</ul>
|
||||
<h2><a class="header" href="#cmc_timer_stop" id="cmc_timer_stop">cmc_timer_stop</a></h2>
|
||||
<p>Sets the <code>stop</code> variable with <code>clock()</code> and calculates the <code>result</code> in milliseconds.</p>
|
||||
<pre><code class="language-c">#define cmc_timer_start(timer)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>timer</code> - A <code>struct cmc_timer</code> variable</li>
|
||||
</ul>
|
||||
<h2><a class="header" href="#example-1" id="example-1">Example</a></h2>
|
||||
<pre><code class="language-c">#include <stdio.h>
|
||||
|
||||
#include "utl/timer.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct cmc_timer t;
|
||||
|
||||
cmc_timer_start(t);
|
||||
|
||||
size_t total = 0;
|
||||
|
||||
for (size_t i = 0; i < 1000000000; i++)
|
||||
total += i;
|
||||
|
||||
cmc_timer_stop(t);
|
||||
|
||||
printf("Sum took %.0lf milliseconds to calculate\n", t.result);
|
||||
}
|
||||
</code></pre>
|
||||
<h1><a class="header" href="#minimal-example" id="minimal-example">Minimal Example</a></h1>
|
||||
<p>(TODO this example is currently outdated)</p>
|
||||
<p>Lets create a list of type <code>int</code>, add some elements to it and get the sum of all the elements printed on the screen.</p>
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
Object.assign(window.search, {"doc_urls":["Introduction/introduction.html#introduction","Introduction/why_this_library.html#why-this-library","Introduction/how_to_install.html#how-to-install","Introduction/library_structure.html#library-structure","Introduction/library_structure.html#cmc","Introduction/library_structure.html#dev","Introduction/library_structure.html#sac","Introduction/library_structure.html#utl","Introduction/library_structure.html#macro_collectionsh","Introduction/understanding_the_library.html#understanding-the-library","Introduction/understanding_the_library.html#sname","Introduction/understanding_the_library.html#pfx","Introduction/understanding_the_library.html#k","Introduction/understanding_the_library.html#v","Introduction/understanding_the_library.html#summarizing","Introduction/how_to_use_the_library.html#how-to-use-the-library","Features/features.html#features","Features/two_way_iterators.html#two-way-iterators","Features/custom_allocation.html#custom-allocation","Features/callbacks.html#callbacks","Features/functions_table.html#functions-table","Features/functions_table.html#cmp","Features/functions_table.html#cpy","Features/functions_table.html#str","Features/functions_table.html#free","Features/functions_table.html#hash","Features/functions_table.html#pri","Overview/overview.html#collections-overview","utl/index.html#utl","utl/index.html#contents","utl/assert.h/index.html#asserth","utl/assert.h/index.html#printed-messages","utl/assert.h/index.html#cmc_assert_state","utl/assert.h/index.html#dtype","utl/assert.h/overview.html#overview","utl/assert.h/overview.html#single-value-assertion-macros","utl/assert.h/overview.html#array-assertion-macros","utl/assert.h/valued_assertions.html#valued-assertion-macros","utl/assert.h/valued_assertions.html#contents","utl/assert.h/valued_assertions.html#cmc_assert","utl/assert.h/valued_assertions.html#cmc_assert_equals","utl/assert.h/valued_assertions.html#cmc_assert_not_equals","utl/assert.h/valued_assertions.html#cmc_assert_greater","utl/assert.h/valued_assertions.html#cmc_assert_greater_equals","utl/assert.h/valued_assertions.html#cmc_assert_lesser","utl/assert.h/valued_assertions.html#cmc_assert_lesser_equals","utl/assert.h/valued_assertions.html#cmc_assert_in_range","utl/assert.h/valued_assertions.html#cmc_assert_not_in_range","utl/assert.h/generic_assertions.html#generic-assertion-macros","utl/assert.h/generic_assertions.html#contents","utl/assert.h/generic_assertions.html#cmc_assert_array_equals_any","utl/assert.h/generic_assertions.html#cmc_assert_array_within_any","utl/assert.h/generic_assertions.html#cmc_assert_array_outside_any","utl/assert.h/generic_assertions.html#cmc_assert_array_sorted_any","utl/foreach.h/index.html#foreachmd","utl/foreach.h/index.html#parameters","utl/log.h/index.html#logh","utl/log.h/index.html#cmc_log_type","utl/log.h/index.html#cmc_log_color","utl/log.h/log_functions.html#log-functions","utl/log.h/log_functions.html#cmc_log_trace","utl/log.h/log_functions.html#cmc_log_debug","utl/log.h/log_functions.html#cmc_log_info","utl/log.h/log_functions.html#cmc_log_warn","utl/log.h/log_functions.html#cmc_log_error","utl/log.h/log_functions.html#cmc_log_fatal","utl/log.h/configuration.html#configuration","utl/log.h/configuration.html#cmc_log_config","utl/log.h/configuration.html#log-level","utl/log.h/meanings.html#meanings","utl/test.h/index.html#testh","utl/timer.h/index.html#timerh","Examples/examples.html#minimal-example","Examples/examples.html#include-headers","Examples/examples.html#generating-a-list","Examples/examples.html#initializing-and-adding-elements","Examples/examples.html#iteration","Examples/examples.html#freeing-resources","Examples/examples.html#compile-and-run","Examples/examples.html#conclusion"],"index":{"documentStore":{"docInfo":{"0":{"body":44,"breadcrumbs":1,"title":1},"1":{"body":122,"breadcrumbs":2,"title":1},"10":{"body":45,"breadcrumbs":2,"title":1},"11":{"body":46,"breadcrumbs":2,"title":1},"12":{"body":11,"breadcrumbs":2,"title":1},"13":{"body":7,"breadcrumbs":2,"title":1},"14":{"body":22,"breadcrumbs":2,"title":1},"15":{"body":12,"breadcrumbs":3,"title":2},"16":{"body":15,"breadcrumbs":1,"title":1},"17":{"body":38,"breadcrumbs":4,"title":3},"18":{"body":20,"breadcrumbs":3,"title":2},"19":{"body":45,"breadcrumbs":2,"title":1},"2":{"body":65,"breadcrumbs":2,"title":1},"20":{"body":22,"breadcrumbs":3,"title":2},"21":{"body":44,"breadcrumbs":2,"title":1},"22":{"body":32,"breadcrumbs":2,"title":1},"23":{"body":20,"breadcrumbs":2,"title":1},"24":{"body":20,"breadcrumbs":2,"title":1},"25":{"body":12,"breadcrumbs":2,"title":1},"26":{"body":184,"breadcrumbs":2,"title":1},"27":{"body":244,"breadcrumbs":2,"title":2},"28":{"body":18,"breadcrumbs":1,"title":1},"29":{"body":5,"breadcrumbs":1,"title":1},"3":{"body":36,"breadcrumbs":3,"title":2},"30":{"body":108,"breadcrumbs":2,"title":1},"31":{"body":89,"breadcrumbs":3,"title":2},"32":{"body":48,"breadcrumbs":2,"title":1},"33":{"body":39,"breadcrumbs":Line truncated
|
||||
Object.assign(window.search, {"doc_urls":["Introduction/introduction.html#introduction","Introduction/why_this_library.html#why-this-library","Introduction/how_to_install.html#how-to-install","Introduction/library_structure.html#library-structure","Introduction/library_structure.html#cmc","Introduction/library_structure.html#dev","Introduction/library_structure.html#sac","Introduction/library_structure.html#utl","Introduction/library_structure.html#macro_collectionsh","Introduction/understanding_the_library.html#understanding-the-library","Introduction/understanding_the_library.html#sname","Introduction/understanding_the_library.html#pfx","Introduction/understanding_the_library.html#k","Introduction/understanding_the_library.html#v","Introduction/understanding_the_library.html#summarizing","Introduction/how_to_use_the_library.html#how-to-use-the-library","Features/features.html#features","Features/two_way_iterators.html#two-way-iterators","Features/custom_allocation.html#custom-allocation","Features/callbacks.html#callbacks","Features/functions_table.html#functions-table","Features/functions_table.html#cmp","Features/functions_table.html#cpy","Features/functions_table.html#str","Features/functions_table.html#free","Features/functions_table.html#hash","Features/functions_table.html#pri","Overview/overview.html#collections-overview","utl/index.html#utl","utl/index.html#contents","utl/assert.h/index.html#asserth","utl/assert.h/index.html#printed-messages","utl/assert.h/index.html#cmc_assert_state","utl/assert.h/index.html#dtype","utl/assert.h/overview.html#overview","utl/assert.h/overview.html#single-value-assertion-macros","utl/assert.h/overview.html#array-assertion-macros","utl/assert.h/valued_assertions.html#valued-assertion-macros","utl/assert.h/valued_assertions.html#contents","utl/assert.h/valued_assertions.html#cmc_assert","utl/assert.h/valued_assertions.html#cmc_assert_equals","utl/assert.h/valued_assertions.html#cmc_assert_not_equals","utl/assert.h/valued_assertions.html#cmc_assert_greater","utl/assert.h/valued_assertions.html#cmc_assert_greater_equals","utl/assert.h/valued_assertions.html#cmc_assert_lesser","utl/assert.h/valued_assertions.html#cmc_assert_lesser_equals","utl/assert.h/valued_assertions.html#cmc_assert_in_range","utl/assert.h/valued_assertions.html#cmc_assert_not_in_range","utl/assert.h/generic_assertions.html#generic-assertion-macros","utl/assert.h/generic_assertions.html#contents","utl/assert.h/generic_assertions.html#cmc_assert_array_equals_any","utl/assert.h/generic_assertions.html#cmc_assert_array_within_any","utl/assert.h/generic_assertions.html#cmc_assert_array_outside_any","utl/assert.h/generic_assertions.html#cmc_assert_array_sorted_any","utl/foreach.h/index.html#foreachmd","utl/foreach.h/index.html#cmc_foreach","utl/foreach.h/index.html#cmc_foreach_rev","utl/log.h/index.html#logh","utl/log.h/index.html#cmc_log_type","utl/log.h/index.html#cmc_log_color","utl/log.h/log_functions.html#log-functions","utl/log.h/log_functions.html#cmc_log_trace","utl/log.h/log_functions.html#cmc_log_debug","utl/log.h/log_functions.html#cmc_log_info","utl/log.h/log_functions.html#cmc_log_warn","utl/log.h/log_functions.html#cmc_log_error","utl/log.h/log_functions.html#cmc_log_fatal","utl/log.h/configuration.html#configuration","utl/log.h/configuration.html#cmc_log_config","utl/log.h/configuration.html#log-level","utl/log.h/meanings.html#meanings","utl/test.h/index.html#testh","utl/test.h/index.html#cmc_create_unit","utl/test.h/index.html#cmc_create_test","utl/test.h/index.html#cmc_test_abort","utl/test.h/index.html#cmc_test_info","utl/test.h/index.html#cmc_test_color","utl/test.h/index.html#example","utl/timer.h/index.html#timerh","utl/timer.h/index.html#cmc_timer","utl/timer.h/index.html#cmc_timer_start","utl/timer.h/index.html#cmc_timer_stop","utl/timer.h/index.html#example","Examples/examples.html#minimal-example","Examples/examples.html#include-headers","Examples/examples.html#generating-a-list","Examples/examples.html#initializing-and-adding-elements","Examples/examples.html#iteration","Examples/examples.html#freeing-resources","Examples/examples.html#compile-and-run","Examples/examples.html#conclusion"],"index":{"documentStore":{"docInfo":{"0":{"body":44,"breadcrumbs":1,"title":1},"1":{"body":122,"breadcrumbs":2,"title":1},"10":{"body":45,"breadcrumbs":2,"title":1},"11":{"body":46,"breadcrumbs":2,"title":1},"12":{"body":11,"breadcrumbs":2,"title":1},"13":{"body":7,"breadcrumbs":2,"title":1},"14":{"body":22,"breadcrumbs":2,"title":1},"15":{"body":12,"breadcrumbs":3,"title":2},"16":{"body":15,"breadcrumbs":1,"title":1},"17":{"body":38,"breadcrumbs":4,"title":3},"18":{"body":20,"breadcrumbs":3,"title":2},"19":{"body":45,"breadcrumbs":2,"title":1},"2":{"body":65,"breadcrumbs":2,"title":1},"20":{"body":22,"breadcrumbs":3,"title":2},"21":{"body":44,"breadcrumbs":2,"title":1},"22":{"body":32,"breadcrumbs":2,"title":1},"23":{"body":20,"breadcrumbs":2,"title":1},"24":{"body":20,"breadcrumbs":2,"title":Line truncated
|
||||
@@ -1 +1 @@
|
||||
{"doc_urls":["Introduction/introduction.html#introduction","Introduction/why_this_library.html#why-this-library","Introduction/how_to_install.html#how-to-install","Introduction/library_structure.html#library-structure","Introduction/library_structure.html#cmc","Introduction/library_structure.html#dev","Introduction/library_structure.html#sac","Introduction/library_structure.html#utl","Introduction/library_structure.html#macro_collectionsh","Introduction/understanding_the_library.html#understanding-the-library","Introduction/understanding_the_library.html#sname","Introduction/understanding_the_library.html#pfx","Introduction/understanding_the_library.html#k","Introduction/understanding_the_library.html#v","Introduction/understanding_the_library.html#summarizing","Introduction/how_to_use_the_library.html#how-to-use-the-library","Features/features.html#features","Features/two_way_iterators.html#two-way-iterators","Features/custom_allocation.html#custom-allocation","Features/callbacks.html#callbacks","Features/functions_table.html#functions-table","Features/functions_table.html#cmp","Features/functions_table.html#cpy","Features/functions_table.html#str","Features/functions_table.html#free","Features/functions_table.html#hash","Features/functions_table.html#pri","Overview/overview.html#collections-overview","utl/index.html#utl","utl/index.html#contents","utl/assert.h/index.html#asserth","utl/assert.h/index.html#printed-messages","utl/assert.h/index.html#cmc_assert_state","utl/assert.h/index.html#dtype","utl/assert.h/overview.html#overview","utl/assert.h/overview.html#single-value-assertion-macros","utl/assert.h/overview.html#array-assertion-macros","utl/assert.h/valued_assertions.html#valued-assertion-macros","utl/assert.h/valued_assertions.html#contents","utl/assert.h/valued_assertions.html#cmc_assert","utl/assert.h/valued_assertions.html#cmc_assert_equals","utl/assert.h/valued_assertions.html#cmc_assert_not_equals","utl/assert.h/valued_assertions.html#cmc_assert_greater","utl/assert.h/valued_assertions.html#cmc_assert_greater_equals","utl/assert.h/valued_assertions.html#cmc_assert_lesser","utl/assert.h/valued_assertions.html#cmc_assert_lesser_equals","utl/assert.h/valued_assertions.html#cmc_assert_in_range","utl/assert.h/valued_assertions.html#cmc_assert_not_in_range","utl/assert.h/generic_assertions.html#generic-assertion-macros","utl/assert.h/generic_assertions.html#contents","utl/assert.h/generic_assertions.html#cmc_assert_array_equals_any","utl/assert.h/generic_assertions.html#cmc_assert_array_within_any","utl/assert.h/generic_assertions.html#cmc_assert_array_outside_any","utl/assert.h/generic_assertions.html#cmc_assert_array_sorted_any","utl/foreach.h/index.html#foreachmd","utl/foreach.h/index.html#parameters","utl/log.h/index.html#logh","utl/log.h/index.html#cmc_log_type","utl/log.h/index.html#cmc_log_color","utl/log.h/log_functions.html#log-functions","utl/log.h/log_functions.html#cmc_log_trace","utl/log.h/log_functions.html#cmc_log_debug","utl/log.h/log_functions.html#cmc_log_info","utl/log.h/log_functions.html#cmc_log_warn","utl/log.h/log_functions.html#cmc_log_error","utl/log.h/log_functions.html#cmc_log_fatal","utl/log.h/configuration.html#configuration","utl/log.h/configuration.html#cmc_log_config","utl/log.h/configuration.html#log-level","utl/log.h/meanings.html#meanings","utl/test.h/index.html#testh","utl/timer.h/index.html#timerh","Examples/examples.html#minimal-example","Examples/examples.html#include-headers","Examples/examples.html#generating-a-list","Examples/examples.html#initializing-and-adding-elements","Examples/examples.html#iteration","Examples/examples.html#freeing-resources","Examples/examples.html#compile-and-run","Examples/examples.html#conclusion"],"index":{"documentStore":{"docInfo":{"0":{"body":44,"breadcrumbs":1,"title":1},"1":{"body":122,"breadcrumbs":2,"title":1},"10":{"body":45,"breadcrumbs":2,"title":1},"11":{"body":46,"breadcrumbs":2,"title":1},"12":{"body":11,"breadcrumbs":2,"title":1},"13":{"body":7,"breadcrumbs":2,"title":1},"14":{"body":22,"breadcrumbs":2,"title":1},"15":{"body":12,"breadcrumbs":3,"title":2},"16":{"body":15,"breadcrumbs":1,"title":1},"17":{"body":38,"breadcrumbs":4,"title":3},"18":{"body":20,"breadcrumbs":3,"title":2},"19":{"body":45,"breadcrumbs":2,"title":1},"2":{"body":65,"breadcrumbs":2,"title":1},"20":{"body":22,"breadcrumbs":3,"title":2},"21":{"body":44,"breadcrumbs":2,"title":1},"22":{"body":32,"breadcrumbs":2,"title":1},"23":{"body":20,"breadcrumbs":2,"title":1},"24":{"body":20,"breadcrumbs":2,"title":1},"25":{"body":12,"breadcrumbs":2,"title":1},"26":{"body":184,"breadcrumbs":2,"title":1},"27":{"body":244,"breadcrumbs":2,"title":2},"28":{"body":18,"breadcrumbs":1,"title":1},"29":{"body":5,"breadcrumbs":1,"title":1},"3":{"body":36,"breadcrumbs":3,"title":2},"30":{"body":108,"breadcrumbs":2,"title":1},"31":{"body":89,"breadcrumbs":3,"title":2},"32":{"body":48,"breadcrumbs":2,"title":1},"33":{"body":39,"breadcrumbs":2,"title":1},"34":{"body":0,"Line truncated
|
||||
{"doc_urls":["Introduction/introduction.html#introduction","Introduction/why_this_library.html#why-this-library","Introduction/how_to_install.html#how-to-install","Introduction/library_structure.html#library-structure","Introduction/library_structure.html#cmc","Introduction/library_structure.html#dev","Introduction/library_structure.html#sac","Introduction/library_structure.html#utl","Introduction/library_structure.html#macro_collectionsh","Introduction/understanding_the_library.html#understanding-the-library","Introduction/understanding_the_library.html#sname","Introduction/understanding_the_library.html#pfx","Introduction/understanding_the_library.html#k","Introduction/understanding_the_library.html#v","Introduction/understanding_the_library.html#summarizing","Introduction/how_to_use_the_library.html#how-to-use-the-library","Features/features.html#features","Features/two_way_iterators.html#two-way-iterators","Features/custom_allocation.html#custom-allocation","Features/callbacks.html#callbacks","Features/functions_table.html#functions-table","Features/functions_table.html#cmp","Features/functions_table.html#cpy","Features/functions_table.html#str","Features/functions_table.html#free","Features/functions_table.html#hash","Features/functions_table.html#pri","Overview/overview.html#collections-overview","utl/index.html#utl","utl/index.html#contents","utl/assert.h/index.html#asserth","utl/assert.h/index.html#printed-messages","utl/assert.h/index.html#cmc_assert_state","utl/assert.h/index.html#dtype","utl/assert.h/overview.html#overview","utl/assert.h/overview.html#single-value-assertion-macros","utl/assert.h/overview.html#array-assertion-macros","utl/assert.h/valued_assertions.html#valued-assertion-macros","utl/assert.h/valued_assertions.html#contents","utl/assert.h/valued_assertions.html#cmc_assert","utl/assert.h/valued_assertions.html#cmc_assert_equals","utl/assert.h/valued_assertions.html#cmc_assert_not_equals","utl/assert.h/valued_assertions.html#cmc_assert_greater","utl/assert.h/valued_assertions.html#cmc_assert_greater_equals","utl/assert.h/valued_assertions.html#cmc_assert_lesser","utl/assert.h/valued_assertions.html#cmc_assert_lesser_equals","utl/assert.h/valued_assertions.html#cmc_assert_in_range","utl/assert.h/valued_assertions.html#cmc_assert_not_in_range","utl/assert.h/generic_assertions.html#generic-assertion-macros","utl/assert.h/generic_assertions.html#contents","utl/assert.h/generic_assertions.html#cmc_assert_array_equals_any","utl/assert.h/generic_assertions.html#cmc_assert_array_within_any","utl/assert.h/generic_assertions.html#cmc_assert_array_outside_any","utl/assert.h/generic_assertions.html#cmc_assert_array_sorted_any","utl/foreach.h/index.html#foreachmd","utl/foreach.h/index.html#cmc_foreach","utl/foreach.h/index.html#cmc_foreach_rev","utl/log.h/index.html#logh","utl/log.h/index.html#cmc_log_type","utl/log.h/index.html#cmc_log_color","utl/log.h/log_functions.html#log-functions","utl/log.h/log_functions.html#cmc_log_trace","utl/log.h/log_functions.html#cmc_log_debug","utl/log.h/log_functions.html#cmc_log_info","utl/log.h/log_functions.html#cmc_log_warn","utl/log.h/log_functions.html#cmc_log_error","utl/log.h/log_functions.html#cmc_log_fatal","utl/log.h/configuration.html#configuration","utl/log.h/configuration.html#cmc_log_config","utl/log.h/configuration.html#log-level","utl/log.h/meanings.html#meanings","utl/test.h/index.html#testh","utl/test.h/index.html#cmc_create_unit","utl/test.h/index.html#cmc_create_test","utl/test.h/index.html#cmc_test_abort","utl/test.h/index.html#cmc_test_info","utl/test.h/index.html#cmc_test_color","utl/test.h/index.html#example","utl/timer.h/index.html#timerh","utl/timer.h/index.html#cmc_timer","utl/timer.h/index.html#cmc_timer_start","utl/timer.h/index.html#cmc_timer_stop","utl/timer.h/index.html#example","Examples/examples.html#minimal-example","Examples/examples.html#include-headers","Examples/examples.html#generating-a-list","Examples/examples.html#initializing-and-adding-elements","Examples/examples.html#iteration","Examples/examples.html#freeing-resources","Examples/examples.html#compile-and-run","Examples/examples.html#conclusion"],"index":{"documentStore":{"docInfo":{"0":{"body":44,"breadcrumbs":1,"title":1},"1":{"body":122,"breadcrumbs":2,"title":1},"10":{"body":45,"breadcrumbs":2,"title":1},"11":{"body":46,"breadcrumbs":2,"title":1},"12":{"body":11,"breadcrumbs":2,"title":1},"13":{"body":7,"breadcrumbs":2,"title":1},"14":{"body":22,"breadcrumbs":2,"title":1},"15":{"body":12,"breadcrumbs":3,"title":2},"16":{"body":15,"breadcrumbs":1,"title":1},"17":{"body":38,"breadcrumbs":4,"title":3},"18":{"body":20,"breadcrumbs":3,"title":2},"19":{"body":45,"breadcrumbs":2,"title":1},"2":{"body":65,"breadcrumbs":2,"title":1},"20":{"body":22,"breadcrumbs":3,"title":2},"21":{"body":44,"breadcrumbs":2,"title":1},"22":{"body":32,"breadcrumbs":2,"title":1},"23":{"body":20,"breadcrumbs":2,"title":1},"24":{"body":20,"breadcrumbs":2,"title":1},"25":{"body":12,"breadcrumLine truncated
|
||||
@@ -154,12 +154,23 @@
|
||||
<li><code>CMC_FOREACH</code> - Goes from the beginning of a Collection to the end</li>
|
||||
<li><code>CMC_FOREAC_REV</code> - Goes from the end of a Collection to the beginning</li>
|
||||
</ul>
|
||||
<h2><a class="header" href="#parameters" id="parameters">Parameters</a></h2>
|
||||
<h2><a class="header" href="#cmc_foreach" id="cmc_foreach">CMC_FOREACH</a></h2>
|
||||
<pre><code class="language-c">#define CMC_FOREACH(PFX, SNAME, ITERNAME, TARGET)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>PFX</code> - Functions prefix</li>
|
||||
<li><code>SNAME</code> - Struct name</li>
|
||||
<li><code>ITERNAME</code> - Iterator variable name</li>
|
||||
<li><code>TARGET</code> - Target variable</li>
|
||||
<li><code>TARGET</code> - Target collection variable name</li>
|
||||
</ul>
|
||||
<h2><a class="header" href="#cmc_foreach_rev" id="cmc_foreach_rev">CMC_FOREACH_REV</a></h2>
|
||||
<pre><code class="language-c">#define CMC_FOREACH_REV(PFX, SNAME, ITERNAME, TARGET)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>PFX</code> - Functions prefix</li>
|
||||
<li><code>SNAME</code> - Struct name</li>
|
||||
<li><code>ITERNAME</code> - Iterator variable name</li>
|
||||
<li><code>TARGET</code> - Target collection variable name</li>
|
||||
</ul>
|
||||
|
||||
</main>
|
||||
|
||||
@@ -149,7 +149,78 @@
|
||||
<div id="content" class="content">
|
||||
<main>
|
||||
<h1><a class="header" href="#testh" id="testh">test.h</a></h1>
|
||||
<p>Simple unit test utility.</p>
|
||||
<p>A simple <a href="https://en.wikipedia.org/wiki/Unit_testing">Unit Test</a> utility used by the C Macro Collections Library. It has two main components: a Unit and a Test.</p>
|
||||
<p>This utility uses two other libraries defined in the C Macro Collections library:</p>
|
||||
<ul>
|
||||
<li><a href="../assert.h/index.html"><code>assert.h</code></a></li>
|
||||
<li><a href="../timer.h/index.html"><code>timer.h</code></a></li>
|
||||
</ul>
|
||||
<p>When a test is created inside a unit, it will first set the global variable <a href="../assert.h/index.html#cmc_assert_state"><code>cmc_assert_state</code></a> to <code>true</code>. Then, inside the test you can use the assertions provided by the <code>assert.h</code> library to pass or fail a unit test automatically. By the end of a test the variable will be checked. If <code>false</code> it means that a certain assertion failed.</p>
|
||||
<p>The runtime of each Unit Test is calculated using the <code>timer.h</code> library.</p>
|
||||
<h2><a class="header" href="#cmc_create_unit" id="cmc_create_unit">CMC_CREATE_UNIT</a></h2>
|
||||
<p>Creates a Unit that can contain tests.</p>
|
||||
<pre><code class="language-c">#define CMC_CREATE_UNIT(UNAME, VERBOSE, BODY)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>UNAME</code> - Unit name. This needs to be a valid function name!</li>
|
||||
<li><code>VERBOSE</code> - Either <code>true</code> or <code>false</code>. If <code>true</code>, prints every message of <code>PASSED</code> or <code>FAILED</code> from each test</li>
|
||||
<li><code>BODY</code> - A block of code containing tests</li>
|
||||
</ul>
|
||||
<h2><a class="header" href="#cmc_create_test" id="cmc_create_test">CMC_CREATE_TEST</a></h2>
|
||||
<p>Creates a test within a unit. This macro can only be used inside the <code>BODY</code> of a <code>CMC_CREATE_UNIT</code> since it uses local variables allocated by the latter.</p>
|
||||
<pre><code class="language-c">#define CMC_CREATE_TEST(TNAME, BODY)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>TNAME</code> - Test name</li>
|
||||
<li><code>BODY</code> - A block of code containing the test itself</li>
|
||||
</ul>
|
||||
<p>Inside a test you can use the assertions from <code>assert.h</code> to automatically pass or fail a test.</p>
|
||||
<h2><a class="header" href="#cmc_test_abort" id="cmc_test_abort">CMC_TEST_ABORT</a></h2>
|
||||
<p>Aborts a unit test. This will jump to a <code>goto</code> located at the end of the Unit Test.</p>
|
||||
<h2><a class="header" href="#cmc_test_info" id="cmc_test_info">cmc_test_info</a></h2>
|
||||
<p>Contains information about a Unit Test. Used internally.</p>
|
||||
<pre><code class="language-c">struct cmc_test_info
|
||||
{
|
||||
uintmax_t total;
|
||||
uintmax_t passed;
|
||||
uintmax_t failed;
|
||||
bool aborted;
|
||||
bool verbose;
|
||||
};
|
||||
</code></pre>
|
||||
<h2><a class="header" href="#cmc_test_color" id="cmc_test_color">CMC_TEST_COLOR</a></h2>
|
||||
<p>Define this macro if you wish to have color output from the messages printed by each test. Note that a Unit Test need to have <code>VERBOSE</code> equal to <code>true</code>.</p>
|
||||
<h2><a class="header" href="#example" id="example">Example</a></h2>
|
||||
<pre><code class="language-c">#include "utl/test.h"
|
||||
|
||||
CMC_CREATE_UNIT(check_math, true, {
|
||||
CMC_CREATE_TEST(summation, {
|
||||
// assert.h already comes with test.h
|
||||
cmc_assert_equals(int32_t, 4, 2 + 2);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(subtraction, {
|
||||
cmc_assert_equals(int32_t, -1, 2 - 3);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(this will fail, {
|
||||
// test names can be text as long as they don't have a comma
|
||||
cmc_assert_greater(double, 1.0, 0.0);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(fish, {
|
||||
// You can also manually fail a test
|
||||
if (strcmp("2 + 2", "fish") != 0)
|
||||
cmc_assert_state = false;
|
||||
});
|
||||
});
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// returns how many tests failed
|
||||
return check_math();
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
</main>
|
||||
|
||||
|
||||
@@ -149,7 +149,55 @@
|
||||
<div id="content" class="content">
|
||||
<main>
|
||||
<h1><a class="header" href="#timerh" id="timerh">timer.h</a></h1>
|
||||
<p>Simple code execution utility.</p>
|
||||
<p>A very simple library that encapsulates <code>clock()</code> from <code><time.h></code>, making life easier.</p>
|
||||
<h2><a class="header" href="#cmc_timer" id="cmc_timer">cmc_timer</a></h2>
|
||||
<pre><code class="language-c">struct cmc_timer
|
||||
{
|
||||
clock_t start;
|
||||
clock_t stop;
|
||||
double result;
|
||||
};
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>clock_t start</code> - Start of timing</li>
|
||||
<li><code>clock_t stop</code> - End of timing</li>
|
||||
<li><code>double result</code> - Result in milliseconds</li>
|
||||
</ul>
|
||||
<h2><a class="header" href="#cmc_timer_start" id="cmc_timer_start">cmc_timer_start</a></h2>
|
||||
<p>Starts the timer by setting <code>start</code> with <code>clock()</code>.</p>
|
||||
<pre><code class="language-c">#define cmc_timer_start(timer)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>timer</code> - A <code>struct cmc_timer</code> variable</li>
|
||||
</ul>
|
||||
<h2><a class="header" href="#cmc_timer_stop" id="cmc_timer_stop">cmc_timer_stop</a></h2>
|
||||
<p>Sets the <code>stop</code> variable with <code>clock()</code> and calculates the <code>result</code> in milliseconds.</p>
|
||||
<pre><code class="language-c">#define cmc_timer_start(timer)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>timer</code> - A <code>struct cmc_timer</code> variable</li>
|
||||
</ul>
|
||||
<h2><a class="header" href="#example" id="example">Example</a></h2>
|
||||
<pre><code class="language-c">#include <stdio.h>
|
||||
|
||||
#include "utl/timer.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct cmc_timer t;
|
||||
|
||||
cmc_timer_start(t);
|
||||
|
||||
size_t total = 0;
|
||||
|
||||
for (size_t i = 0; i < 1000000000; i++)
|
||||
total += i;
|
||||
|
||||
cmc_timer_stop(t);
|
||||
|
||||
printf("Sum took %.0lf milliseconds to calculate\n", t.result);
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
</main>
|
||||
|
||||
|
||||
@@ -5,9 +5,24 @@ For-Each macros. Since doing a for loop with iterators can be a lot to write, th
|
||||
* `CMC_FOREACH` - Goes from the beginning of a Collection to the end
|
||||
* `CMC_FOREAC_REV` - Goes from the end of a Collection to the beginning
|
||||
|
||||
## Parameters
|
||||
## CMC_FOREACH
|
||||
|
||||
```c
|
||||
#define CMC_FOREACH(PFX, SNAME, ITERNAME, TARGET)
|
||||
```
|
||||
|
||||
* `PFX` - Functions prefix
|
||||
* `SNAME` - Struct name
|
||||
* `ITERNAME` - Iterator variable name
|
||||
* `TARGET` - Target variable
|
||||
* `TARGET` - Target collection variable name
|
||||
|
||||
## CMC_FOREACH_REV
|
||||
|
||||
```c
|
||||
#define CMC_FOREACH_REV(PFX, SNAME, ITERNAME, TARGET)
|
||||
```
|
||||
|
||||
* `PFX` - Functions prefix
|
||||
* `SNAME` - Struct name
|
||||
* `ITERNAME` - Iterator variable name
|
||||
* `TARGET` - Target collection variable name
|
||||
@@ -1,4 +1,94 @@
|
||||
# test.h
|
||||
|
||||
Simple unit test utility.
|
||||
A simple [Unit Test](https://en.wikipedia.org/wiki/Unit_testing) utility used by the C Macro Collections Library. It has two main components: a Unit and a Test.
|
||||
|
||||
This utility uses two other libraries defined in the C Macro Collections library:
|
||||
|
||||
* [`assert.h`](../assert.h/index.html)
|
||||
* [`timer.h`](../timer.h/index.html)
|
||||
|
||||
When a test is created inside a unit, it will first set the global variable [`cmc_assert_state`](../assert.h/index.html#cmc_assert_state) to `true`. Then, inside the test you can use the assertions provided by the `assert.h` library to pass or fail a unit test automatically. By the end of a test the variable will be checked. If `false` it means that a certain assertion failed.
|
||||
|
||||
The runtime of each Unit Test is calculated using the `timer.h` library.
|
||||
|
||||
## CMC_CREATE_UNIT
|
||||
|
||||
Creates a Unit that can contain tests.
|
||||
|
||||
```c
|
||||
#define CMC_CREATE_UNIT(UNAME, VERBOSE, BODY)
|
||||
```
|
||||
|
||||
* `UNAME` - Unit name. This needs to be a valid function name!
|
||||
* `VERBOSE` - Either `true` or `false`. If `true`, prints every message of `PASSED` or `FAILED` from each test
|
||||
* `BODY` - A block of code containing tests
|
||||
|
||||
## CMC_CREATE_TEST
|
||||
|
||||
Creates a test within a unit. This macro can only be used inside the `BODY` of a `CMC_CREATE_UNIT` since it uses local variables allocated by the latter.
|
||||
|
||||
```c
|
||||
#define CMC_CREATE_TEST(TNAME, BODY)
|
||||
```
|
||||
|
||||
* `TNAME` - Test name
|
||||
* `BODY` - A block of code containing the test itself
|
||||
|
||||
Inside a test you can use the assertions from `assert.h` to automatically pass or fail a test.
|
||||
|
||||
## CMC_TEST_ABORT
|
||||
|
||||
Aborts a unit test. This will jump to a `goto` located at the end of the Unit Test.
|
||||
|
||||
## cmc_test_info
|
||||
|
||||
Contains information about a Unit Test. Used internally.
|
||||
|
||||
```c
|
||||
struct cmc_test_info
|
||||
{
|
||||
uintmax_t total;
|
||||
uintmax_t passed;
|
||||
uintmax_t failed;
|
||||
bool aborted;
|
||||
bool verbose;
|
||||
};
|
||||
```
|
||||
|
||||
## CMC_TEST_COLOR
|
||||
|
||||
Define this macro if you wish to have color output from the messages printed by each test. Note that a Unit Test need to have `VERBOSE` equal to `true`.
|
||||
|
||||
## Example
|
||||
|
||||
```c
|
||||
#include "utl/test.h"
|
||||
|
||||
CMC_CREATE_UNIT(check_math, true, {
|
||||
CMC_CREATE_TEST(summation, {
|
||||
// assert.h already comes with test.h
|
||||
cmc_assert_equals(int32_t, 4, 2 + 2);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(subtraction, {
|
||||
cmc_assert_equals(int32_t, -1, 2 - 3);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(this will fail, {
|
||||
// test names can be text as long as they don't have a comma
|
||||
cmc_assert_greater(double, 1.0, 0.0);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(fish, {
|
||||
// You can also manually fail a test
|
||||
if (strcmp("2 + 2", "fish") != 0)
|
||||
cmc_assert_state = false;
|
||||
});
|
||||
});
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// returns how many tests failed
|
||||
return check_math();
|
||||
}
|
||||
```
|
||||
@@ -1,3 +1,63 @@
|
||||
# timer.h
|
||||
|
||||
Simple code execution utility.
|
||||
A very simple library that encapsulates `clock()` from `<time.h>`, making life easier.
|
||||
|
||||
## cmc_timer
|
||||
|
||||
```c
|
||||
struct cmc_timer
|
||||
{
|
||||
clock_t start;
|
||||
clock_t stop;
|
||||
double result;
|
||||
};
|
||||
```
|
||||
|
||||
* `clock_t start` - Start of timing
|
||||
* `clock_t stop` - End of timing
|
||||
* `double result` - Result in milliseconds
|
||||
|
||||
## cmc_timer_start
|
||||
|
||||
Starts the timer by setting `start` with `clock()`.
|
||||
|
||||
```c
|
||||
#define cmc_timer_start(timer)
|
||||
```
|
||||
|
||||
* `timer` - A `struct cmc_timer` variable
|
||||
|
||||
## cmc_timer_stop
|
||||
|
||||
Sets the `stop` variable with `clock()` and calculates the `result` in milliseconds.
|
||||
|
||||
```c
|
||||
#define cmc_timer_start(timer)
|
||||
```
|
||||
|
||||
* `timer` - A `struct cmc_timer` variable
|
||||
|
||||
## Example
|
||||
|
||||
```c
|
||||
#include <stdio.h>
|
||||
|
||||
#include "utl/timer.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct cmc_timer t;
|
||||
|
||||
cmc_timer_start(t);
|
||||
|
||||
size_t total = 0;
|
||||
|
||||
for (size_t i = 0; i < 1000000000; i++)
|
||||
total += i;
|
||||
|
||||
cmc_timer_stop(t);
|
||||
|
||||
printf("Sum took %.0lf milliseconds to calculate\n", t.result);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -101,7 +101,6 @@ static void cmc_test_log(const char *unit_name, const char *current_test,
|
||||
BODY; \
|
||||
\
|
||||
cmc_timer_stop(timer); \
|
||||
cmc_timer_calc(timer); \
|
||||
\
|
||||
unittest_abort: \
|
||||
if (tinfo.aborted) \
|
||||
|
||||
+12
-20
@@ -24,28 +24,20 @@ struct cmc_timer
|
||||
double result; /* The result is given in milliseconds */
|
||||
};
|
||||
|
||||
#define cmc_timer_start(timer) \
|
||||
do \
|
||||
{ \
|
||||
struct cmc_timer *t = &(timer); \
|
||||
t->start = clock(); \
|
||||
\
|
||||
#define cmc_timer_start(timer) \
|
||||
do \
|
||||
{ \
|
||||
struct cmc_timer *t__ = &(timer); \
|
||||
t__->start = clock(); \
|
||||
} while (0)
|
||||
|
||||
#define cmc_timer_stop(timer) \
|
||||
do \
|
||||
{ \
|
||||
struct cmc_timer *t = &(timer); \
|
||||
t->stop = clock(); \
|
||||
\
|
||||
} while (0)
|
||||
|
||||
#define cmc_timer_calc(timer) \
|
||||
do \
|
||||
{ \
|
||||
struct cmc_timer *t = &(timer); \
|
||||
t->result = (double)(t->stop - t->start) * 1000.0 / CLOCKS_PER_SEC; \
|
||||
\
|
||||
#define cmc_timer_stop(timer) \
|
||||
do \
|
||||
{ \
|
||||
struct cmc_timer *t__ = &(timer); \
|
||||
t__->stop = clock(); \
|
||||
t__->result = \
|
||||
(double)(t__->stop - t__->start) * 1000.0 / CLOCKS_PER_SEC; \
|
||||
} while (0)
|
||||
|
||||
#endif /* CMC_TIMER_H */
|
||||
@@ -40,7 +40,6 @@ int main(void)
|
||||
failed += treeset_test();
|
||||
|
||||
cmc_timer_stop(timer);
|
||||
cmc_timer_calc(timer);
|
||||
|
||||
printf("+--------------------------------------------------+\n");
|
||||
printf("| Total running time : %14.0lf milliseconds |\n", timer.result);
|
||||
|
||||
Reference in new issue
Block a user