小编spe*_*ric的帖子

为什么执行时间为"for($ i = 1; $ i -le 1000000; $ i ++){}"比"for([int] $ i = 1; $ i -le 1000000; $ i ++){}"更快电源外壳

示例代码:

# Step 1
$start = get-date
for($i=1; $i -le 1000000; $i++){}
$end = get-date
($end-$start).TotalMilliseconds
Remove-Variable i

# Step 2
$start = get-date
for([int]$i=1; $i -le 1000000; $i++){}
$end = get-date
($end-$start).TotalMilliseconds
Remove-Variable i

# Step 3
$start = get-date
for([int64]$i=1; $i -le 1000000; $i++){}
$end = get-date
($end-$start).TotalMilliseconds
Remove-Variable i

# Step 4
$start = get-date
for([float]$i=1; $i -le 1000000; $i++){}
$end = get-date
($end-$start).TotalMilliseconds
Remove-Variable i

# Step 5
$start = get-date
for([double]$i=1; $i -le 1000000; $i++){} …
Run Code Online (Sandbox Code Playgroud)

powershell

7
推荐指数
1
解决办法
351
查看次数

标签 统计

powershell ×1