FIBT (Comparing Program-Execution Time)
FIB1 calculates intermediate values Fi more than once, while FIB2 calculates each intermediate Fi only once. Consequently, FIB2 is faster. The difference in speed increases with the size of n because the time required for FIB1 grows exponentially with n, while the time required for FIB2 grows only linearly with n.
FIBT executes the TICKS command to record the execution time of FIB1 and FIB2 for a given value of n.
Level 1 | → | Level 3 | Level 2 | Level 1 |
|
|
|
|
|
n | → | Fn | FIB1 TIME: z | FIB2 TIME: z |
|
|
|
|
|
Techniques used in FIBT
Structured programming. FIBT calls both FIB1 and FIB2.
Programmatic use of calculator clock. FIBT executes the TICKS command to record the start and finish of each subprogram.
Labeling output. FIBT tags each execution time with a descriptive message.
Required Programs
FIB1 (page
FIB2 (page
FIBT program listing
|
| Program: | Comments: |
|
|
|
|
|
| « |
|
|
| DUP TICKS SWAP | Copies n, then executes FIB1, recording the |
|
| FIB1 SWAP TICKS SWAP | start and stop time. |
|
| - B→R 8192 / | Calculates the elapsed time, converts it to a |
|
|
| real number, and converts that number to |
|
|
| seconds. |
|
|
| Leaves the answer returned by FIB1 in level 2. |
|
| "FIB1 TIME" →TAG | Tags the execution time. |
|
| ROT TICKS SWAP FIB2 | Executes FIB2, recording the start and stop |
|
| TICKS | time. |
|
| SWAP DROP SWAP | Drops the answer returned by FIB2 (FIB1 |
|
| - B→R 8192 / | returned the same answer). Calculates the |
|
|
| elapsed time for FIB2 and converts to seconds. |
|
| "FIB2 TIME" →TAG | Tags the execution time. |
|
| » |
|
|
|
|
|
|
| `OFIBT K | Stores the program in FIBT. |
|
|
| |
|
|
| |
Checksum: # 23164d |
| ||
Bytes: | 129 |
|