proj: Add perf/
This commit is contained in:
33
proj/perf/main.c
Normal file
33
proj/perf/main.c
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(const int argc, const char *argv[]) {
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: main <cycles>\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
const long cycles = strtol(argv[1], NULL, 10);
|
||||
|
||||
struct timespec start, end;
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
|
||||
int pipes[2];
|
||||
for (int i = 0; i < cycles; i++) {
|
||||
if (pipe(pipes) != 0) {
|
||||
fprintf(stderr, "unable to create pipes: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
close(pipes[0]);
|
||||
close(pipes[1]);
|
||||
}
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
const long duration = end.tv_sec * 1000000000 + end.tv_nsec - start.tv_sec * 1000000000 - start.tv_nsec;
|
||||
printf("start: %li.%09li\nend: %li.%09li\nduration: %li,%03li,%03li ns\n", start.tv_sec, start.tv_nsec, end.tv_sec, end.tv_nsec, duration / 1000000, duration / 1000 % 1000, duration % 1000);
|
||||
}
|
||||
Reference in New Issue
Block a user