Created
September 3, 2016 05:51
-
-
Save tanakamura/a82475c8269228267c4e90cecfc271f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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