-4

What are the solutions to increase the speed of the program in C ++? My program is very slow and I want to increase the speed

crtT
  • 1
  • 1
    Seems a duplicate of this https://stackoverflow.com/questions/2030189/general-c-performance-improvement-tips – davide-pi Dec 08 '20 at 08:13
  • 1
    Without knowing anything about your program it's hard to give advice. – Jabberwocky Dec 08 '20 at 08:17
  • Does this answer your question? [General C++ Performance Improvement Tips](https://stackoverflow.com/questions/2030189/general-c-performance-improvement-tips) – davide-pi Dec 08 '20 at 08:17
  • The subject of a wikipedia page: [program optimization](https://en.wikipedia.org/wiki/Program_optimization). Note this sentence (by Donald Knuth): *premature optimization is the root of all evil* – Damien Dec 08 '20 at 08:36
  • a very common cause for slow execution is forgetting to turn on compiler optimizations. Often that is all you need – 463035818_is_not_an_ai Dec 08 '20 at 08:38
  • Avoid accessing the hard disk. – eerorika Dec 08 '20 at 09:29

1 Answers1

1

Here are some tips you can use to speed up any program:

  • Do memoizing/caching - instead of calculating the same value over and over again, save it and simply recall it from memory later.
  • Do batch IO - instead of writing/reading character by character or line by line, store them in memory and then read/write a bunch of characters or lines at the same time.
  • Use faster algorithms - instead of using brute force, use tree search, use dictionaries/hashes/array indices for faster access. Aim for smaller values of big-o.
nurettin
  • 11,090
  • 5
  • 65
  • 85