Skip to content

Instantly share code, notes, and snippets.

@tanakamura
Created September 3, 2016 05:51
Show Gist options
  • Save tanakamura/a82475c8269228267c4e90cecfc271f3 to your computer and use it in GitHub Desktop.
Save tanakamura/a82475c8269228267c4e90cecfc271f3 to your computer and use it in GitHub Desktop.
#include <unistd.h>
#include <stdio.h>
#include <time.h>
double sec(void) {
struct timespec tv;
clock_gettime(CLOCK_MONOTONIC, &tv);
return tv.tv_sec + tv.tv_nsec / (1000000000.0);
}
static void
test(void)
{
int nloop = 1024, pid, li;
double t0 = sec(), t1;
for (li=0; li<nloop; li++) {
int st;
pid = fork();
if (pid == 0) {
_exit(0);
}
wait(&st);
}
t1 = sec();
printf("fork() %f [msec]\n", ((t1-t0)/nloop)*1000.0);
}
int main()
{
test();
test();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment