Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Timeline for Tips for golfing in PowerShell

Current License: CC BY-SA 3.0

9 events
when toggle format what by license comment
Nov 15, 2013 at 14:54 comment added Iszi Another interesting bit: An alias e.g.: nal g random seems to not be functional in PS 2.0. The alias gets created, but it's unresolvable when you try to use it - even though random works. The alias worked fine (minus the lag) in 4.0.
Nov 15, 2013 at 14:49 comment added Iszi That could be it. I did some math and figured my Monty Hall script should take about 1.5 hours (normally, 10-11 seconds) to run without Get-. That's a pretty gnarly bloat in run time for a savings of just 4 characters in length.
Nov 15, 2013 at 14:47 comment added Joey I suspect it is because of what I added in the answer this morning – the implied Get- seems to be after everything else in the command lookup list, which means everything on the PATH needs to be checked first. I cannot look into the implementation though, lest I want to be unable to continue working on Pash.
Nov 15, 2013 at 14:43 comment added Iszi Wow. It looks like the same probably holds true for any alias. Tested Get-Variable vs. gv and got a similar comparison.
Nov 15, 2013 at 6:23 comment added Iszi My problem was running 10,000 iterations of the Monty Hall scenario each requiring three iterations of Get-Random. A 50,000% increase in processing time, multiplied across 30,000 runs is pretty nasty.
Nov 15, 2013 at 6:18 comment added Joey Two short Measure-Command invocations (100 times Get-Random vs. random) tell me it's about 500 times slower. I didn't know that before, to be honest. But it's good to keep it in mind, especially in loops with many iterations. That being said, golfed code should be short, not fast (that being said, it sucks to have to wait two days for an answer to a Project Euler problem).
Nov 15, 2013 at 6:15 history edited Joey CC BY-SA 3.0
added 490 characters in body
Nov 15, 2013 at 0:56 comment added Iszi This doesn't quite always work out as expected. I have a script that starts with nal g Get-Random to save characters later on. Changing it to nal g Random causes the script to hang indefinitely (or, at least, take an inordinate amount of time to process - I haven't had the patience to wait for it to end, but it's taking several orders of magnitude longer than the original form before I abort).
Feb 9, 2011 at 19:22 history answered Joey CC BY-SA 2.5

AltStyle によって変換されたページ (->オリジナル) /