Time a function: Difference between revisions

add RPL
(add →‎Joy)
(add RPL)
Line 2,333:
</syntaxhighlight>
 
=={{header|RPL}}==
In its first versions, RPL did not provide user access to system clock - but advacanced users know which system call can be made on their machine to get it. The following code works on a 1987 HP-28S, but can crash on older ones and will surely do on on other machines.
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! RPL code
! Comment
|-
|
#11CAh SYSEVAL → tick
≪ EVAL
#11CAh SYSEVAL tick -
B→R 8192 / 1 FIX RND STD
≫ ≫ ‘'''TIMER'''’ STO
|
'''TIMER''' ''( ≪function≫ -- execution_time )''
Store current system time
Execute function
Measure difference in CPU cycles
convert to seconds, round to one decimal place
|}
{{in}}
<pre>
≪ 1 1000 START NEXT ≫ TIMER
</pre>
{{out}}
<pre>
1: 6.4
</pre>
Yes, more than 6 seconds to loop 1000 times is quite slow.
=={{header|Ruby}}==
Ruby's Benchmark module provides a way to generate nice reports (numbers are in seconds):
1,150

edits