Skip to content

Instantly share code, notes, and snippets.

@bdolgov
Created May 8, 2017 22:01
Show Gist options
  • Save bdolgov/539214149042830318e0f8e5073ea274 to your computer and use it in GitHub Desktop.
Save bdolgov/539214149042830318e0f8e5073ea274 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
const char *sd_cmd[] = {"/usr/bin/systemd-run", "--scope", "/usr/bin/sleep",
"0.005", NULL};
// Bash is used to perform some random syscalls to make this test more fair.
const char *nosd_cmd[] = {"/bin/bash", "-c", "/usr/bin/sleep 0.005", NULL};
#define HEAT 10
#define N 10
int main(int argc, char **argv, char **envp) {
int heat = HEAT;
int count = N;
double sum = 0;
time_t prev = time(NULL);
int iterations = 0;
while (count) {
if (!fork()) {
execve(CMD[0], CMD, envp);
} else {
wait(NULL);
}
++iterations;
time_t now = time(NULL);
if (prev != now) {
prev = now;
if (heat) {
--heat;
} else {
sum += iterations;
iterations = 0;
--count;
}
}
}
printf("Result: %lf\n", sum / N);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment