import os import subprocess from time import time print("pid: %s" % os.getpid()) a=time() for i in range(10000): if 0: # 19081.1 ms pid = os.fork() if pid == 0: os.execv("/bin/false", ["/bin/false"]) else: os.waitpid(pid, 0) elif 0: # 25769.8 ms f = os.popen("/bin/false") f.close() elif 1: # unpatched: 40025.8 ms # patched: 26155.2 ms f = subprocess.Popen(["/bin/false"], shell=False) f.wait() b=time()-a print("Time: %.1f ms" % (b*1000))