Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Can anyone help me run this C program faster, it takes long to execute completely..!?

0
Posted

Can anyone help me run this C program faster, it takes long to execute completely..!?

0

First of all this looks a lot like a school assignment, but I am going to trust you. The first thing I did was to turn on optimizations on the compiler. I assume that you have already done something like that, but I was able to make it run much faster by doing that. For gcc it is -O3 Next I ran a profiler and 91% of the time was beign spent in fibonacci. So I rewrote it to not recalculate everything that you already know. If you do go with a much larger number of loops try moving the fib cache off of the stack and onto the heap. You may need to look at ways to optimize the prime number checker then too. Before 7.533s After 0.004s #include # define FALSE 0 /**Value Representing False for NOT PRIME**/ # define TRUE 1 /**Value Representing True for IS PRIME**/ #define NUM_LOOPS 40 int isprime(long fib); /**Function prototype for isprime**/ long fibonacci (long n, long * fib); /**Function prototype for nextFib**/ int main (void) { long num; long prime; long fib; long fib_cache[NU

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123