multithreadingperformancefactorialprocessors

Does processor count affect the performance of a single-threaded program?


My program is a simple recursive implementation of the factorial function. Is its execution speed related to the number of processors on my computer? My program is not multi-threaded.


Solution

  • No, it is not related to the number of processors. Since your program is not multithreaded, it will run in only a single thread, which runs on a single processor at a time.

    The speed of a single processor is not increased by the existence of other processors on a computer, except that having more processors may allow other programs to run on other cores, thus allowing your program to use a larger fraction of the single processor that it is running on.

    As Raymond Chen pointed out in the comments, there are also complicated issues with caching that may come up if your thread is migrated across CPUs, which occurs regularly.

    Of course, these are likely to be relative small effects overall - and, certainly, you generally can't expect a program to run faster on a computer with more processors unless the program is multithreaded.