I decided getting two other codes, where the fork()
and the thread would do:
void do_nothing() {
int i;
i = 0;
}
The best way I've found to calculate the time, was executing the invoking the time. For n = 50000
I've obtained:
$ time ./forks
real 0m25.064s
user 0m3.389s
sys 0m12.731s
$ time ./pthreads
real 0m2.164s
user 0m0.262s
sys 0m1.616s
So, I created processes using fork()
and created (and destroyed) threads that simply created a variable and gave the value 0
to them.