5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PowerShell は配列の扱いでスピードが変わるらしい

Last updated at Posted at 2016-06-22

ブログからの転載

PowerShell で配列の扱い方でスピードが変わるらしい
あまり細かいことは良いから、実感が欲しかったので下記コードでテストした

検証コード

+= を使った


検証コード1.ps1
Measure-Command {
    $hoge  = New-Object System.Collections.ArrayList
    foreach($i in 1..$max) {
        $hoge += ($i)
    }
}

Add を使った


検証コード2.ps1
Measure-Command {
    $hoge  = New-Object System.Collections.ArrayList
    foreach($i in 1..$max) {
        $hoge.Add($i)
    }
}

結果

+= を使った


回数 かかった時間(ミリ秒)
$max = 100 23.6538
$max = 1000 63.8938
$max = 10000 2882.8444
$max = 100000 336124.8685

Add を使った


回数 かかった時間(ミリ秒)
$max = 100 0.8989
$max = 1000 8.9539
$max = 10000 50.2974
$max = 100000 245.2522
5
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?