Monday, July 20, 2009

making c codes faster

some basic tricks for speeding up c codes:
  • division is much slower than multiplication
  • log10(), sqrt() are also very slow -- should avoid using these unless absolutely necessary
  • inlines can be of tremendous help, as it may be easier for the compiler to optimize
  • a for loop like for(i=1;i<=10;i++) can be re-written as for(i=10;i--;), which may save a little bit of time
more tricks can be found here

No comments: