Improve Powershell Performance to Generate a Random File

后端 未结 4 1191
花落未央
花落未央 2020-12-10 23:09

I\'d like to user Powershell to create a random text file for use in basic system testing (upload, download, checksum, etc). I\'ve used the following articles and co

4条回答
  •  执念已碎
    2020-12-10 23:48

    One of the bottlenecks is calling the get-random cmdlet in the loop. On my machine that join takes ~40ms. If you change to something like:

    %{ -join ((get-random -InputObject $chars -Count 62) + (get-random -InputObject $chars -Count 62) + (get-random -InputObject $chars -Count 2)) }
    

    it is reduced to ~1ms.

提交回复
热议问题