Test Average
---- -------
Byte-by-Byte Comparison 57.832
Chunk Comparison 1.223
Last active
August 27, 2023 08:32
-
-
Save santisq/fba25efd7bbe221107cf86a8853abd74 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0..10 | ForEach-Object { | |
Measure-Command {&{ | |
$fileA = (Get-Item .\lorem1.txt).OpenRead() | |
$fileB = (Get-Item .\lorem2.txt).OpenRead() | |
for(($i = 0), ($z = 0); $i -lt $fileA.Length -or $z -lt $fileB.Length; $i++, $z++) { | |
if(-not $fileA.ReadByte().Equals($fileB.ReadByte())) { | |
break | |
} | |
} | |
($fileA, $fileB).ForEach('Dispose') | |
}} | Select-Object @{ N = 'Test'; E = { 'Byte-by-Byte Comparison' }}, TotalMilliseconds | |
Measure-Command {&{ | |
$fileA = (Get-Item .\lorem1.txt).OpenRead() | |
$fileB = (Get-Item .\lorem2.txt).OpenRead() | |
$bufferA = [byte[]]::new(1kb) | |
$bufferB = [byte[]]::new(1kb) | |
while(0 -notin $fileA.Read($bufferA, 0, $bufferA.Length), $fileB.Read($bufferB, 0, $bufferB.Length)) { | |
if(-not [System.Linq.Enumerable]::SequenceEqual($bufferA, $bufferB)) { | |
break | |
} | |
} | |
($fileA, $fileB).ForEach('Dispose') | |
}} | Select-Object @{ N = 'Test'; E = { 'Chunk Comparison' }}, TotalMilliseconds | |
} | Group-Object Test | Select-Object @( | |
@{ N = 'Test'; E = { $_.Name }} | |
@{ N = 'Average'; E = { | |
[math]::Round([System.Linq.Enumerable]::Average([double[]] $_.Group.TotalMilliseconds), 3) | |
}} | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
& { param($FirstFile, $SecondFile) | |
try { | |
$fileA = (Get-Item $FirstFile).OpenRead() | |
$fileB = (Get-Item $SecondFile).OpenRead() | |
$bufferA = [byte[]]::new(1kb) | |
$bufferB = [byte[]]::new(1kb) | |
while(0 -notin $fileA.Read($bufferA, 0, $bufferA.Length), $fileB.Read($bufferB, 0, $bufferB.Length)) { | |
if(-not [System.Linq.Enumerable]::SequenceEqual($bufferA, $bufferB)) { | |
return $false | |
} | |
$true | |
} | |
} | |
finally { | |
${fileA}?.Dispose() | |
${fileB}?.Dispose() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment