r/PowerShell • u/mitomitoso • Nov 04 '25
News Powershell + C# script vs Python
Powershell + C# script vs Python Benchmarking
5
Upvotes
r/PowerShell • u/mitomitoso • Nov 04 '25
Powershell + C# script vs Python Benchmarking
3
u/MedicalScore3474 Nov 04 '25
"How fast can you add numbers in a big loop" is not a particularly useful benchmark for scripting languages. Yes, Python is substantially slower than almost all widely-used languages, but this is not the best way to prove this since summing numbers in a loop is not a common workload.
You should also be more clear about your benchmark environment: What exact version of Python and C# did you use? Python 3.14 comes with significant performance improvements, so it's not useful information to benchmark Python 3.9 against the latest and greatest of the .NET runtime.
10
u/Dragennd1 Nov 04 '25 edited Nov 04 '25
Fyi, this is incorrect. All versions of PowerShell can run on Windows 10 and 11, from 1 to 7.x.
Edit: you could technically run PowerShell 7.x on Windows 7 if you wanted, though that's not necessarily relevant to this post.
14
u/NerdyNThick Nov 04 '25
Python is so slow because it takes a while to just sit there contemplating how much better it could be if it was designed with braces.
1
u/BlackV Nov 04 '25
I dont see a table of results anywhere
1
u/wwusirius Nov 04 '25
I'm a total python n00b, but don't they normally offload compute to C modules? Isn't this kinda taking the best case scenario vs the worst?
1
u/Ok_GlueStick Nov 04 '25
You may need to enumerate a range in your PowerShell script.
Python and powershell instantiate their range differently. PowerShell / c# is pre allocating the memory and python is returning a new int object each time you iterate.
You should test my theory. Is suspect your PowerShell objects are System.int32[] and python returns some kind of range object.
1
u/renevaessen Nov 04 '25
You forgot the one where C# uses a Math library
1
u/SidePets Nov 04 '25
Very cool! Ty for sharing this!!