-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemcpy.c
51 lines (39 loc) · 978 Bytes
/
memcpy.c
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <err.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
#include "dummy.h"
static bool loop = true;
static void
signal_handler(int sig)
{
if (sig == SIGALRM)
loop = false;
}
#define LOOP(seconds, counter) \
if (alarm(seconds) == (unsigned int)-1) \
err(EXIT_FAILURE, "alarm"); \
for (loop = true, counter = 0; loop; counter++)
int
main(void)
{
size_t counter;
unsigned int seconds = 5;
size_t size = 128 * 1024 * 1024;
char *src = malloc(size);
char *dst = malloc(size);
signal(SIGALRM, signal_handler);
uint8_t *s = (uint8_t *) src;
uint8_t *d = (uint8_t *) dst;
LOOP(seconds, counter)
for (; s < (uint8_t *)src + size; *d++ = *s++);
printf("%zu\n", counter / seconds);
// LOOP(seconds, counter)
// memcpy(dst, src, size);
// printf("%zu\n", counter / seconds);
return EXIT_SUCCESS;
}