Had to wirte and optimize a C++ program that finds for 1000x1000x1000 grid points the 100 nearest points for each (with an additional factor to make it more complicated).
It had to run in under 18 minutes to pass. No matter what I did I couldn't get it fast enough. I tried kd-trees, caching of certain points, optimizing distamce calculations by ommiting any irrelevant factor, saving points' calculated squares etc etc. When Ibwas down to 20 minutes, I realized, that my makefile had an error and ignored the - O3 flag...
Well, it actually ran 5 minutes with -O3.

  • 21
    There is so much YES in this story!
  • 7
    Yep, did a similar rant few days back, but the impact of -O is just magic.

    I mean if you check the assembly code produced with -O0, you'd see that almost every line of code actually accesses the memory even for the most mundane things. That slows down your programs by a friggin lot.

    One more reason why I can't part with C/++ <3
  • 7
    C++ is not my l;anguage, but I found this page :


    (I was looking for something else, but this is even better lol).

    BTW, Even Java/.Net compilers are insane in optimization
  • 3
    @NoToJavaScript I had a class on parallel programming and we used Java for practical examples. At one point someone complained that His Code ran waaaaay slower than anyone elses and it took a while for us to figure Out that He hast optimization disabled. Slower by a Factor of around 10 If I remember correctly
  • 0
    Are you using PCL?
    I did something similar a few years ago, and the runtime wasn't that bad...
  • 0
    @NickyBones No, it was a university project sonwe had to get every library confirmed by our supervisors,
    I got one kd tree library accepted the rest was plain C++
  • 0
    And I assume as a main Java dev, my C++ code probably isn't the most elegant
  • 1
    @Katakompe Then I have some criticism on your supervisors :)
    PCL is literally the industry standard for handling point clouds. They have pretty solid documentation too, so you can learn about the algorithms, and the library is well written - it's always beneficial to see good coding examples.
    I can't understand people who insist on reinventing the wheel....
  • 0
    @NoToJavaScript neat. Thanks!
  • 0
    @NoToJavaScript Wow, that recursion fix up is really neat. As well as the built in call fix.

    All hail the GCC! I am so glad at my current job we have standardized on gcc and mingw
Add Comment