Time a function: Difference between revisions
Content added Content deleted
(Lingo added) |
(Added FreeBASIC) |
||
Line 690: | Line 690: | ||
end |
end |
||
</lang> |
</lang> |
||
=={{header|FreeBASIC}}== |
|||
<lang freebasic>' FB 1.05.0 Win64 |
|||
Function sumToLimit(limit As UInteger) As UInteger |
|||
Dim sum As UInteger = 0 |
|||
For i As UInteger = 1 To limit |
|||
sum += i |
|||
Next |
|||
Return sum |
|||
End Function |
|||
Dim As Double start = timer |
|||
Dim limit As UInteger = 100000000 |
|||
Dim result As UInteger = sumToLimit(limit) |
|||
Dim ms As UInteger = Int(1000 * (timer - start) + 0.5) |
|||
Print "sumToLimit("; Str(limit); ") = "; result |
|||
Print "took "; ms; " milliseconds to calculate" |
|||
Print |
|||
Print "Press any key to quit" |
|||
Sleep</lang> |
|||
{{out}} |
|||
<pre> |
|||
sumToLimit(100000000) = 5000000050000000 |
|||
took 314 milliseconds to calculate |
|||
</pre> |
|||
=={{header|GAP}}== |
=={{header|GAP}}== |