4 ms·
I'm not a huge fan of PowerShell but you're not really making a good comparison here. Bash is "just a shell" that executes commands with a few bits of syntacti
by riskable 10y ago
I'm not a huge fan of PowerShell but you're not really making a good comparison here. Bash is "just a shell" that executes commands with a few bits of syntactic sugar here and there to make it easier to string those commands together and perform some primitive logic.
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.
- jasonjayr 10y agoI fully agree -- they're two different animals. IMHO, it's a symptom of the two different paradigms of running a process on Windows vs Unix. 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.
- Grishnakh 10y agoSo I wonder how it compares to having the python interpreter open. According to my machine, running the python interpreter results in 1 PID, 129M virt, 4.6M res.
- jasonjayr 10y agoUsing java + jython, results in 15 pids, 2010M Virt / 196M 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'.
- vacri 10y agoLooked at from another direction, the unix world works beautifully with slim VMs, unlike windows which requires gigabytes of ram. There are plenty of 0.5GB ram unix VMs out there that do their job just fine... and to fork over 20% of that ram just to do shell scripting? Not very portable.
- temac 10y agoI'm not so sure it results in a vastly faster execution, at least on OSes which don't need half an hour to spawn a new process. So, yes, of course it was needed for Windows, because there creating a new process is so expensive that sometimes you've got to mortgage your house to do it.
- riskable 10y agoI was going to cover this topic (the cost of starting/forking a process) in my original comment but decided it would be a bit tangential since I was able to make my point without it. 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.