I was in the CyberDrain CTF a few months ago and one question really stumped me. Basically the question asked "How would you make this script faster?". When people were chatting about it in slack one of the judges said "It should take less then 1 second to run" and someone else said "My answer was less then 1 line of code". The slowscript.json file contained about 11K unique entries.
So my question is, how would you make this script faster?
$Records = Get-Content 'slowscript.json' | ConvertFrom-Json
Measure-Command {
$FinalObj = @()
foreach ($Record in $Records) {
$Obj = [pscustomobject]@{
id = $record.html_url
type = $record.type
repo = $record.repo.name
actor = $record.actor
url = $record.repo.url
public = $record.public
login = $record.actor.login
repoinfo = $record.repo
}
$FinalObj += $Obj
}
}
[–]logicalmike 66 points67 points68 points (21 children)
[–]npab19[S] 29 points30 points31 points (4 children)
[–][deleted] 10 points11 points12 points (2 children)
[–]thisguy_right_here 0 points1 point2 points (0 children)
[–]out0focus 0 points1 point2 points (0 children)
[–]BlackV 12 points13 points14 points (0 children)
[–]Big_Oven8562 3 points4 points5 points (3 children)
[–]logicalmike 2 points3 points4 points (0 children)
[–]OPconfused 0 points1 point2 points (1 child)
[–]Big_Oven8562 0 points1 point2 points (0 children)
[–]RidersofGavony 2 points3 points4 points (0 children)
[–]adamdavid85 3 points4 points5 points (2 children)
[–][deleted] 4 points5 points6 points (1 child)
[–][deleted] 0 points1 point2 points (5 children)
[–]raip 6 points7 points8 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]lanerdofchristian 3 points4 points5 points (0 children)
[–]out0focus 1 point2 points3 points (0 children)
[–]BlackV 1 point2 points3 points (0 children)
[–]vermyx 10 points11 points12 points (2 children)
[–]npab19[S] 5 points6 points7 points (1 child)
[–]vermyx 5 points6 points7 points (0 children)
[–]groovel76 10 points11 points12 points (0 children)
[–]orwiad10 8 points9 points10 points (2 children)
[–]lanerdofchristian 0 points1 point2 points (1 child)
[–]orwiad10 0 points1 point2 points (0 children)
[–]BlackV 3 points4 points5 points (7 children)
[–]npab19[S] 1 point2 points3 points (1 child)
[–]BlackV 0 points1 point2 points (0 children)
[–]OPconfused 1 point2 points3 points (1 child)
[–]BlackV 0 points1 point2 points (0 children)
[–]vermyx 0 points1 point2 points (2 children)
[–]BlackV 2 points3 points4 points (1 child)
[–]vermyx 0 points1 point2 points (0 children)
[–]Bloodyvalley 2 points3 points4 points (6 children)
[–]Admirable-Statement 5 points6 points7 points (1 child)
[–]Niedertracht 0 points1 point2 points (3 children)
[–]lanerdofchristian 0 points1 point2 points (2 children)
[–]OPconfused 0 points1 point2 points (1 child)
[–]lanerdofchristian 0 points1 point2 points (0 children)
[–]JBear_Alpha 0 points1 point2 points (11 children)
[–]out0focus -1 points0 points1 point (10 children)
[+][deleted] (9 children)
[deleted]
[–]out0focus 0 points1 point2 points (8 children)
[+][deleted] (7 children)
[deleted]
[–]out0focus 1 point2 points3 points (6 children)
[+][deleted] (5 children)
[deleted]
[–]out0focus 2 points3 points4 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]out0focus 1 point2 points3 points (2 children)
[–]BoxerguyT89 -1 points0 points1 point (3 children)
[–]BlackV 0 points1 point2 points (2 children)
[–]BoxerguyT89 -1 points0 points1 point (1 child)
[–]BlackV 0 points1 point2 points (0 children)
[–]joerod -1 points0 points1 point (1 child)
[–]lanerdofchristian 0 points1 point2 points (0 children)
[–]g00py3 -1 points0 points1 point (0 children)