Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PowerShell Challenge – Beating Hadoop with Posh
<#
http://foxdeploy.com/2016/03/01/powershell-challenge-beating-hadoop-with-posh/
9m 25s 643ms on my machine, Core i5-2500K @ 3.30Ghz
Only uses a single core so there is much room to improve.
Update $Path to point to the folder containing the folders of .pgn files.
Change "select -First 10" to "select -First 1" for quick test runs.
#>
$Path = 'V:\ChessData Project\ChessData-master\ChessData-master'
Set-Location -Path $Path
Measure-Command -Expression {
[int]$W = 0
[int]$B = 0
[int]$D = 0
Get-ChildItem -Directory | sort Name | select -First 10 | % {
Get-ChildItem -Path $_.FullName -File -Filter *.pgn | % {
Write-Verbose "$($_.FullName) $($($_.length)/1MB)" -Verbose
$CurrentFile = New-Object System.IO.StreamReader($_.FullName)
while (($CurrentLine = $CurrentFile.ReadLine()) -ne $null) {
if ($CurrentLine -match 'result'){
$M = (($CurrentLine -split '-')[0]).ToString()[-1]
if($M -eq '2'){$D++}elseif($M -eq '1'){$B++}elseif($M -eq '0'){$W++}
}
}
$CurrentFile.Close()
}
}
$Result = [pscustomobject]@{
White = $W
Black = $B
Draw = $D
}
}
$Result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.