나는 이진 파일 나는 진 구문 분석의 세부 사항에 가고 싶지 않아PowerShell을 - 이진 파일 성능이 저하
Param(
[Parameter(Mandatory=$True)]
[string]$inputFilePath
)
function GetLengthFrom2Byte
{
Param(
[Parameter(Mandatory=$True)]
[byte[]]$bytes
)
if ($bytes.Length -ne 2)
{
echo "Parametro di Input non valido"
}
else
{
$lenByte = New-Object Byte[](2)
$lenByte[0] = $bytes[1]
$lenByte[1] = $bytes[0]
return [BitConverter]::ToUInt16($lenByte, 0)
}
}
try
{
if (!(Test-Path($inputFilePath)))
{
Throw "File di Input non valido: <{0}>" -f $inputFilePath
}
$inputStream = New-Object IO.FileStream($inputFilePath, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::Read)
$inputBinaryReader = New-Object IO.BinaryReader($inputStream)
while ($inputBinaryReader.PeekChar() -ne -1)
{
$AfpHeader = $inputBinaryReader.ReadByte()
if ($AfpHeader -ne 0x5A)
{
Throw "Errore nella struttura AFP. Byte 0x5A non trovato all' offset: <{0}>" -f $inputBinaryReader.BaseStream.Position
exit 8
}
$AfpLength = $inputBinaryReader.ReadBytes(2)
$recordLength = GetLengthFrom2Byte($AfpLength)
$inputBinaryReader.ReadBytes($recordLength - 2) > $null
}
echo "File AFP Validato"
}
catch [Exception]
{
echo "Errore: {0}" -f $error[0]
exit 8
}
finally
{
$inputBinaryReader.Dispose()
$inputStream.Dispose()
}
exit 0
을 구문 분석 다음 코드를 작성했습니다. 문제는 PowerShell에서 11 분이 걸린 반면 C#의 동일한 기능은 약 50 초가 걸렸습니다.
동일한 클래스를 사용하고 있기 때문에 왜 그 차이가 너무 큰지 알 수 없습니다. PowerShell 성능을 향상시킬 방법이 있습니까?
$lenByte = New-Object Byte[](2)
를 그래서 그냥 한 번 발생하는 것이 : 당신이 스크립트 범위에이 라인을 이동하는 경우
정확히 무엇이 문제입니까? –
PowerShell이 해석되는 동안 C#이 컴파일된다는 것을 알고 있습니까? –
@EugenRieck 네, 저도 압니다 만, 그 차이가 너무 크지는 않습니까? –