aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/fill_buffer/fill_buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/monniaux/fill_buffer/fill_buffer.c')
-rw-r--r--test/monniaux/fill_buffer/fill_buffer.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/monniaux/fill_buffer/fill_buffer.c b/test/monniaux/fill_buffer/fill_buffer.c
new file mode 100644
index 00000000..a83267f5
--- /dev/null
+++ b/test/monniaux/fill_buffer/fill_buffer.c
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "../clock.h"
+
+typedef unsigned char data;
+
+void fill_buffer(data x, unsigned n, data *buf) {
+ for(unsigned i=0; i<n; i++) buf[i] = x;
+}
+
+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_buffer2(42, n, buf);
+ clock_stop();
+ free(buf);
+ print_total_clock();
+ return 0;
+}