7
示例代码:
# 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++){}
$end = get-date
($end-$start).TotalMilliseconds
Remove-Variable i
# Step 6
$start = get-date
for($i=1; $i -le 1000000; $i++){}
$end = get-date
($end-$start).TotalMilliseconds
Remove-Variable i
结果:
1845.1056
3160.1808
5029.2877
5521.3158
4504.2576
1804.1032
没有关于步骤2-6之间的差异问题。但1和2和6之间的区别是不可理解的:$ i在这些情况下具有类型“System.Int32”。
我看到的结果与您大致相同。 –
测量执行时间的方式本质上没有什么错,但是为了将来的测试,您可能需要在提示符下检查:get-help测量命令 – EBGreen
有趣的是,如果您执行'$ i = new -object -type Int64'或'$ i = new-object -type Int32'然后'for($ i = 1; $ i -le 1000000; $ i ++){}',你会得到类似的结果整数)。在那个演员操作符或许... – zdan