diff options
author | David Monniaux <david.monniaux@univ-grenoble-alpes.fr> | 2019-02-04 18:40:31 +0100 |
---|---|---|
committer | David Monniaux <david.monniaux@univ-grenoble-alpes.fr> | 2019-02-04 18:40:31 +0100 |
commit | 2d24cf64acc5c63a31efa676ab5b11d2fba0f641 (patch) | |
tree | 5300745603dd9054466615139645a4696b9a4540 /test/monniaux/loop/fill_buffer.c | |
parent | a6d367a87ad94515a8a1d13b0cee45696656e4cb (diff) | |
download | compcert-kvx-2d24cf64acc5c63a31efa676ab5b11d2fba0f641.tar.gz compcert-kvx-2d24cf64acc5c63a31efa676ab5b11d2fba0f641.zip |
note on cycles
Diffstat (limited to 'test/monniaux/loop/fill_buffer.c')
-rw-r--r-- | test/monniaux/loop/fill_buffer.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/monniaux/loop/fill_buffer.c b/test/monniaux/loop/fill_buffer.c new file mode 100644 index 00000000..9d89a2d1 --- /dev/null +++ b/test/monniaux/loop/fill_buffer.c @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <stdlib.h> +#include "../clock.h" + +typedef unsigned char data; + +/* 8 cycles / iteration */ +void fill_buffer(data x, unsigned n, data *buf) { + for(unsigned i=0; i<n; i++) buf[i] = x; +} + +/* 7 cycles / iteration */ +void fill_buffer2(data x, unsigned n, data *buf) { + unsigned i=0; + if (i<n) { + do { + buf[i] = x; + i++; + } while (i<n); + } +} + +void fill_buffer10(data x, data *buf) { + for(unsigned i=0; i<10; i++) buf[i] = x; +} + +int main() { + const size_t n = 10000; + data *buf = malloc(n * sizeof(data)); + clock_prepare(); + clock_start(); + fill_buffer(42, n, buf); + clock_stop(); + free(buf); + print_total_clock(); + return 0; +} |