by jasonjayr · 10y ago · 0 comments
powershell, 14 pids(threads?), 3119M Virt size, 80160kb Resident.
bash, 1 pid, 22068kb Virt, 3976kb Resident.
And this is simply starting the process to an idle prompt.
This is on a Debian 8 64bit system. (using their Ubuntu 14.04 binary)
PowerShell is basically an interpreter that works more like a Java Virtual Machine. Consider the hypothetical example that you need to lookup 100 users in an LDAP directory from Bash: You run the openldap command 100 times in a loop. That's 100 processes that need to fork and quit in a serial fashion in order to perform the task at hand.
To do the same thing in PowerShell you'll be calling a native PowerShell LDAP API which will execute all 100 lookups without having to fork any separate process resulting in a vastly faster execution.
It's better to think of PowerShell like the Python or Ruby interpreters. IMHO, PowerShell is a vastly superior improvement to cmd.exe as a shell but on a Unix host it will be inferior to bash for day-to-day tasks.
I worry about getting out of the habit when scripting on Linux of forking off a new process for each iteration of a loop, rather than pushing the loop into powershell, for better execution.
According to my machine, running the python interpreter results in 1 PID, 129M virt, 4.6M res.
Jython is probably the more apt comparison, vs the compiled interpreter. But, it falls into the same trap as powershell: You couldn't invoke jython in a loop like you would 'python' or 'perl'.
On Windows the cost of forking a process is high whereas on Unix/Linux it's low but on both platforms every application has a nontrivial startup time that will be significantly greater than a native call within an existing process.