3 ms·
Let's consider ten thousand forks. $ cat winforktest.sh #!/home/busybox-1.35 sh i=1; while [ $i -lt 10000 ]; do (echo $i); i=$((i+1)); done On Linux, t
by chasil 1y ago
Let's consider ten thousand forks.
$ cat winforktest.sh
#!/home/busybox-1.35 sh
i=1; while [ $i -lt 10000 ]; do (echo $i); i=$((i+1)); done
On Linux, this takes:
$ cat /etc/redhat-release
Red Hat Enterprise Linux release 8.10 (Ootpa)
$ time ./winforktest.sh > /dev/null
real 0m0.792s
user 0m0.490s
sys 0m0.361s
On Windows,
c:\users\x>ver
Microsoft Windows [Version 10.0.22631.5472]
c:\users\x>busybox | busybox head -2
BusyBox v1.37.0-FRP-5236-g7dff7f376 (2023-12-06 10:31:32 GMT)
(mingw64-gcc 13.2.1-5.fc39; mingw64-crt 11.0.0-2.fc39; glob)
c:\users\x>busybox sh
~ $ time ./winforktest > /dev/null
real 3m 44.44s
user 0m 0.32s
sys 0m 4.90s
Windows is quite a bit slower, at least with Busybox.
I understand that WSLv1 presents a more efficient fork(), which is not really available to shims like Cygwin or mingw.
- kragen 1y agoThank you very much! So, that does 19999 fork()s in 224 seconds, which works out to about 11 milliseconds per fork(). (On my Linux box, it's actually doing clone(), and also does a bunch of wait4(), rt_sigaction(), exit_group(), etc., but let's assume the fork() is the bottleneck.) This is pretty slow, but it's still about 6× faster than the 70 milliseconds I had inferred from your "100× slower than any other POSIX". Also note that your Red Hat machine is evidently forking in 39μs, which is several times faster than I've ever seen Linux fork.