aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/fill_buffer/fill_buffer.c
blob: a83267f5275965ea1921c4acf4b863d9fd447537 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
}