Skip to content

Instantly share code, notes, and snippets.

@gn0
Last active July 17, 2025 18:55
Show Gist options
  • Save gn0/63c2a7ec13a7ac867ff39cce6357b261 to your computer and use it in GitHub Desktop.
Save gn0/63c2a7ec13a7ac867ff39cce6357b261 to your computer and use it in GitHub Desktop.
Primitive benchmark to measure process startup time
/* a.c, compiled to ./a */
void main() {}
/* b.c, compiled to ./b */
#include <sys/wait.h>
#include <unistd.h>
int main() {
for (size_t i = 0; i < 100 * 1000; i++) {
if (fork() == 0) {
execve("./a", (char*[]){ NULL }, (char*[]){ NULL });
} else {
int wstatus;
wait(&wstatus);
}
}
}
/* Then on a Core i7:
$ gcc a.c -O0 -o ./a
$ gcc b.c -O3 -o ./b
$ time ./b
real 1m3.293s
user 0m26.689s
sys 0m34.515s
This implies 63.293 s * 1000 / 100000 =~ 633 μs of wall clock time per execution of ./a.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment