Compile-time calculation: Difference between revisions

Content added Content deleted
No edit summary
Line 705: Line 705:
=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang PowerShell>
<lang PowerShell>
function fun($n){
function fact([BigInt]$n){
if($n -ge ([BigInt]::Zero)) {
$res = 0
$fact = [BigInt]::One
if($n -gt 0) {
1..$n | foreach{
([BigInt]::One)..$n | foreach{
$a, $b = $_, ($n+$_)
$fact = [BigInt]::Multiply($fact, $_)
$res += $a + $b
}
}
$fact

} else {
Write-Error "$n is lower than 0"
}
}
$res
}
}
"$((Measure-Command {fun 10000}).TotalSeconds) Seconds"
"$((Measure-Command {$fact = fact 10}).TotalSeconds) Seconds"
$fact
</lang>
</lang>
<b>Output:</b>
<b>Output:</b>
<pre>
<pre>
0.820712 Seconds
0.0030411 Seconds
3628800
</pre>
</pre>