diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2014-06-20 22:55:59 -0500 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2014-06-20 22:55:59 -0500 |
commit | 5fa0d5023f0e2935f99b04422f3a338d77264107 (patch) | |
tree | d3ce357870a0a816cbda5add42ea14f0fce94053 /generators.c |
Initial commit: benchmark musl's qsort
Diffstat (limited to 'generators.c')
-rw-r--r-- | generators.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/generators.c b/generators.c new file mode 100644 index 0000000..002b128 --- /dev/null +++ b/generators.c @@ -0,0 +1,34 @@ +#include <limits.h> +#include <stddef.h> +#include <stdlib.h> + +#include "generators.h" + +static void generate_random(int *buffer, size_t size) +{ + srandom(1); + for (size_t i = 0; i < size; i++) buffer[i] = random(); +} + +static void generate_sorted(int *buffer, size_t size) +{ + for (size_t i = 0; i < size; i++) buffer[i] = i; +} + +static void generate_reverse(int *buffer, size_t size) +{ + for (size_t i = 0; i < size; i++) buffer[i] = INT_MAX - i; +} + +static void generate_constant(int *buffer, size_t size) +{ + for (size_t i = 0; i < size; i++) buffer[i] = 42; +} + +const struct generator generators[] = { + { .name = "random", .func = generate_random }, + { .name = "sorted", .func = generate_sorted }, + { .name = "reverse", .func = generate_reverse }, + { .name = "constant", .func = generate_constant }, + { 0 } +}; |