Time a function: Difference between revisions

Content added Content deleted
(Time a function in True BASIC)
(add BQN)
Line 699: Line 699:
REM perform processing
REM perform processing
lapsed%=TIME-start%</lang>
lapsed%=TIME-start%</lang>

=={{header|BQN}}==
To execute a function <code>F</code> once and get the amount of time it took to execute with value <code>v</code>, you can do this:
<lang bqn>F ā€¢_timed v</lang>
<code>ā€¢_timed</code> is a system value that runs <code>F</code> a set number of times and returns the average runtime of the function. Here, since the left argument <code>š•Ø</code> is omitted, it is run once.

The final result is in seconds.

Here are a few example runs:
<lang bqn> {0:1;š•©Ć—š•Šš•©-1}ā€¢_timed 100
8.437800000000001eĀÆ05
{0:1;š•©Ć—š•Šš•©-1}ā€¢_timed 1000
0.000299545</lang>



=={{header|Bracmat}}==
=={{header|Bracmat}}==