18

That long took to display "Ave user!" 32,000,000 times

Comments
  • 6
    ye printing is expensive..
    and 32M is really a lot 😂
  • 8
    Technically, it took longer because it had to print the current iteration.
  • 6
    CodeBlocks and light theme...
    Please do yourself a favour and use Visual Studio, CLion, or any of the more sophisticated editors (VSC, etc.)

    Also, no kidding. To print it has to trap into the OS and fiddle with graphics. Very expensive operation.
  • 5
    Yeah, do the exact same code without the actual printing and it'll take an infinitesimally smaller amount of time to run.
  • 3
    @RememberMe I use Visual Studio, dark theme. I have to use CodeBlocks because tomorrow I participate to a contest that uses CodeBlocks and I must get used with it.

    I'll repeat the test with no print.
  • 1
    @dandrei279 Ah, I see.
    Also, here's some interesting stuff about C++ I/O:

    http://drdobbs.com/the-standard-lib...

    Also, if you're using endl I *think* it flushes the stream, try with "\n" instead. And maybe write to a buffer and print the buffer in large chunks? (Though I/O should buffer anyway, not sure if this would increase performance).
  • 4
    Use multithreading.
  • 1
  • 2
    You could generate a huge string and only print it once. Then you wouldn't have that print calls and it'd be faster I think. Should test it...

    @martikyan ew. Pls stop
  • 1
    A solution to the slow printing, store your output in a large buffer and when it's getting close to being full, print it and empty it. Repeat.
  • 1
    printf() is super slow, I think cout would be faster since it's a stream, could be super wrong though.
  • 2
    @olback you are super wrong....
    Printf is faster than cout
    If you are in competitive coding especially, you must know this
  • 0
    @faheel but there was this one question I did an year back, where it didn't go as expected...
    Even using sync_with_stdio(false) make it TLE but scanf and printf made it.
    Tbh one shouldn't devise such test cases and constrains
Add Comment