Recent

Author Topic: [Resolved]why does it take so long?  (Read 4189 times)

rabbit_dance

  • Full Member
  • ***
  • Posts: 157
[Resolved]why does it take so long?
« on: October 02, 2015, 11:44:13 am »
http://forum.lazarus.freepascal.org/index.php/topic,29782.0.html
running $ ./euler_phi takes inestimable long time.
why?
« Last Edit: October 02, 2015, 04:00:35 pm by rabbit_dance »

derek.john.evans

  • Guest
« Last Edit: October 02, 2015, 01:18:48 pm by Geepster »

rabbit_dance

  • Full Member
  • ***
  • Posts: 157
Re: why does it take so long?
« Reply #2 on: October 02, 2015, 02:53:32 pm »
http://forum.lazarus.freepascal.org/index.php/topic,29782.0.html
running $ ./euler_phi takes inestimable long time.
why?
sorry, i said something wrong just now.
it's $ ./euler_phi
10003
enter

derek.john.evans

  • Guest
Re: why does it take so long?
« Reply #3 on: October 02, 2015, 03:07:27 pm »
http://forum.lazarus.freepascal.org/index.php/topic,29782.0.html
running $ ./euler_phi takes inestimable long time.
why?
sorry, i said something wrong just now.
it's $ ./euler_phi
10003
enter

Same answer. Look at other implementations. How do you know your code is taking a long time, if you dont compare it to other code?

All the answers are in the links above. The first one has two implementations. The second quotes this:
Quote
Another solution if you’re short in memory would not use Sieve of Eratosthenes. This way requires more processing.

IE: This way requires more processing. The author is very clear on the up/down sides to his implementation. "More memory/faster" vs "less memory/slower".

Basically, if your code is taking a long time (compared to another algorithm), then, there often isn't any simple fix. You need to code another algorithm.

Its like asking, why is my bubblesort so slow? Because... bubblesorts are slow. Simple.

Most books Ive seen, teach this topic in the context of sorting algorithms. If you haven't learnt that, then you have skipped a lot of knowledge you need to understand why an algorithm is fast/slow and how to optimize algorithms.

https://en.wikipedia.org/wiki/Algorithmic_efficiency
http://www.cprogramming.com/tutorial/computersciencetheory/sortcomp.html
http://rosettacode.org/wiki/Compare_sorting_algorithms'_performance

So, I cant see how someone can explain it to you.

If you understand your code, then thats a great achievement. But, the fact is, if you want to implement the best algorithm for a given task, then you need to learn how to implement pre-designed algorithms.

Thats just how you do it. So, you need to learn to read other peoples code.
« Last Edit: October 02, 2015, 03:10:19 pm by Geepster »

rabbit_dance

  • Full Member
  • ***
  • Posts: 157
Re: why does it take so long?
« Reply #4 on: October 02, 2015, 03:08:03 pm »
if i'm root, the executing process will be much faster.
#/home/wu/euler_phi
10003

rabbit_dance

  • Full Member
  • ***
  • Posts: 157
Re: why does it take so long?
« Reply #5 on: October 02, 2015, 03:19:00 pm »
i found the reason why the program takes so long, i was then compiling linux kernel.
it become more faster than that time.please close the topic.

Bart

  • Hero Member
  • *****
  • Posts: 5727
    • Bart en Mariska's Webstek
Re: why does it take so long?
« Reply #6 on: October 02, 2015, 03:39:59 pm »
You can mark it as [Resolved] by editing your first post in this topic and adding "[Resolved] " (without the quotes) in front of the topic titel.

Bart

 

TinyPortal © 2005-2018