Post Reply 
Example Program to calculate Factorial
02-02-2018, 05:05 AM
Post: #17
RE: Example Program to calculate Factorial
(02-02-2018 03:41 AM)Gamo Wrote:  When we make our own program somehow the internal function compute faster than programs version. Is this due to the advantage of build-in functions is in ROM or algorithm formula program is better than our own program? Like these factorial programs.
For modern 12C+ or 15C LE no speed differences.

It is possible that the ROM uses a better algorithm, but in the case of n!, I think the basic multiplication is used everywhere.

The reason user programs are slower than ROM routines is because of the extra work the calculator has to do while executing user code: it has to fetch the user code instructions from memory, then decode and execute them, one by one for each program step.

When it is running a ROM routine, only the machine code that performs the calculation is executed; when it is running user code, it has to do all that work *and* the work of decoding and executing the user code instructions.

How much that overhead adds up to depends on various details, and can vary a lot. For example, on my HP-42S, calculating 253! with the built-in N! function takes about 2 seconds, while the program takes about 12 seconds, so 6 times slower; in Free42, the program is only 1.5 times slower than the built-in function.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Example Program to calculate Factorial - Thomas Okken - 02-02-2018 05:05 AM



User(s) browsing this thread: 4 Guest(s)