6 ms·
Author makes a comment that "If we just run /bin/true, we can do 500 of them in a second" -- this is very platform dependent -- i think Linux' process creation
by exacube 11y ago
Author makes a comment that "If we just run /bin/true, we can do 500 of them in a second" -- this is very platform dependent -- i think Linux' process creation is supposed to be 1-2 orders of magnitude faster than Windows, for example (i don't have the exact numbers though).
- kps 11y agoProcesses and files on Windows are heavyweight. I recall once speeding up a script by about 100 times by changing something of the form a >>$LOG b >>$LOG ⋮ c >>$LOG to { a b ⋮ c } >>$LOG
- LukeShu 11y agoThe implementation of true also makes a difference! Not quite an order of magnitude difference, though (except for the shell builtin). method Hz comment -------------------------------------------------------- empty file 500 an empty file gets passed to /bin/sh dynamic libc 1000 "int main { return 0; }" -> gcc static libc 1500 the same, but with "gcc -static" assembly 2000 see below bash builtin 150000 avoids hitting the kernel or filesystem The empty file is the "traditional" implementation of true on Unix. The assembly solution was my attempt at doing the littlest amount possible, because libc initialization still takes time: .globl _start _start: movl $1, %eax # %eax = SYS_exit xorl %ebx, %ebx # %ebx = 0 (exit status) int $0x80
- kragen 11y agoThis depends in part on how big the process that's forking is. http://canonical.org/~kragen/sw/dev3/server.s http://canonical.org/~kragen/sw/dev3/server.s manages to get quite a bit more than 2000 forks per second out of Linux, which might be in part because it only has two to four virtual memory pages mapped. (see http://canonical.org/~kragen/sw/dev3/httpdito-readme http://canonical.org/~kragen/sw/dev3/httpdito-readme for more details.)