22 lines
544 B
C
22 lines
544 B
C
|
|
#include <stdio.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <string.h>
|
||
|
|
#include <time.h>
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
struct timespec t1, t2;
|
||
|
|
void* buf = malloc(2 * 1024 * 1024);
|
||
|
|
|
||
|
|
clock_gettime(CLOCK_MONOTONIC, &t1);
|
||
|
|
memset(buf, 0xEF, 2 * 1024 * 1024);
|
||
|
|
clock_gettime(CLOCK_MONOTONIC, &t2);
|
||
|
|
|
||
|
|
double ms = (t2.tv_sec - t1.tv_sec) * 1000.0 + (t2.tv_nsec - t1.tv_nsec) / 1000000.0;
|
||
|
|
|
||
|
|
printf("memset time: %.3f ms\n", ms);
|
||
|
|
printf("First byte: 0x%02x (should be 0xEF)\n", ((unsigned char*)buf)[0]);
|
||
|
|
|
||
|
|
free(buf);
|
||
|
|
return 0;
|
||
|
|
}
|