經由函數「參數列」傳遞$buffer
function aa($buffer){
write-host "$(get-date)"
}
$buffer = new-object byte[](20MB)
write-host "$(get-date)"
aa $buffer
PowerShell 5.0 - 執行正常
PS R:\> .\test.ps1 09/16/2020 12:08:06 09/16/2020 12:08:06
PowerShell 2.0 - 速度變慢
PS R:\> powershell -v 2
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS R:\> .\test.ps1
09/16/2020 12:08:40
09/16/2020 12:08:47
不經由函數「參數列」傳遞$buffer
function aa(){
$buffer = $script:buffer
write-host "$(get-date)"
}
$buffer = new-object byte[](20MB)
write-host "$(get-date)"
aa
PowerShell 5.0 - 執行正常
PS R:\> .\test.ps1 09/16/2020 12:42:43 09/16/2020 12:42:43
PowerShell 2.0 - 執行正常
PS R:\> powershell -v 2 Windows PowerShell Copyright (C) 2009 Microsoft Corporation. All rights reserved. PS R:\> .\test.ps1 09/16/2020 12:42:57 09/16/2020 12:42:57
沒有留言:
張貼留言