Optimized my program fron running 74 minutes to running 0.005 seconds. I call that a successful day.

  • 35

    Its an EPIC day

  • 22
    74 minutes?
  • 7
    What did you compute?
  • 36
    @monkcs the circumference of the universe and Pi at the same time apparently
  • 101
    @vortexman100 …or maybe moved the return statement to the begining of main()? πŸ˜‰
  • 27
    @monkcs Thanks for the tip! I'll make sure I use that technique in every program I write from now on
  • 11
  • 21
    Maybe He wanted to calculate PI for 10000000 decimal places and now found out he could just copy already know decimals and paste them into His codeπŸ€”
  • 5
    Why was it that slow in the first way? πŸ˜…
  • 0
    @monkcs hahaha that was funny
  • 3
    Does it still work like before? πŸ™ƒ
  • 5
    I feel dumb since i was excited from turning a 10 million insterts from a query, from 1.5 minutes to 1.1 minutes :(
  • 19
    I am using something like a linked list + struct pointer, which is filled by a push function. This function loops over the entire list and appends to the last node. I removed the function and merged it with the filler loop (which is linux' nftw() btw) and made one string array in the struct to a string pointer, because otherwise the program allocates 4kb ram per node. Now the program only needs 0.005 seconds and ram usage went from 2.5 GB to 180 MB.
  • 3
    @monkcs I collected all data about every file in a soecific directory. In this case, my main NAS, which has about 6 TB files.
  • 4
    @monkcs Well, i honestly thought that. I checked everything, including printing out and core dumps. It worked.
  • 2
    @PenguinRage @wolt Well, when using liked lists the push function costs rises lineary, because it has to loop over everything. The nftw function has a callback function, which previously just called push(). Now i stored the current node in a global variable, which allows the callback to remember the position of its last append. So, performance never decreases. If you want i can give you the repo link :)
  • 2
    @eis6aer Oh, no, dont feel stupid. I had and now have to do exactly the same.
  • 2
    Maybe you have caching on? And the next run read it from cache πŸ€”
  • 12
    So before it lasted 74 mins before it would crash, now it takes 0.005 seconds to crash? πŸ˜‹
  • 6
    Facepalm. Your original approach was very flawed.

    Saving a pointer to the last node is a solution, as is passing the pointer to your push function. You should avoid using global vars, though
  • 2
    @Ashkin Yes, it was. But it is my first use of datastructures other than arrays.
  • 7
    @vortexman100 you're forgiven, then.
  • 41
    To quote my old computer architecture professor: when you write a software add useless loops around to have bad performances and release /sell as version 1.0, then remove some of them and release version 2.0 with "hey buy version 2.0, it is n times faster than 1.0"
  • 6
  • 1
    Nice job. But I wonder how the 74min thing was accepted at the first place
    It seems it's obvious something wrong.
  • 1
    My code won't run so fast, even without something written in it ._.
  • 4
    @krazycavin Its my project and i am the only one working on it, so...
  • 13
    did you remove sleep(1234567890123456) from your code?
  • 1
  • 4
    On the other hand, you had created a program that actually needed 0.005 seconds and took 74 minutes. That's a really bad day!
  • 2
    @tmux Maaaaaan, just let me feel good!
  • 5
    @vortexman100 you should feel good. You came back to refactor. You are better than 99% of us from this alone.
  • 4
    @tmux "You came back to refactor" sounds a bit like "You came back to take revenge and your rightful place as the king" or something...
  • 4
    @m93mark Probably that's why the quality of open-source software is better than closed source ones. "No shit, just git!"
  • 2
    int main() {
    return 42; // fixes performance issue
    // return computeAnswerToLifeTheUniverseAndEverything();
Add Comment