Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7857943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:12:03+00:00 2026-06-02T21:12:03+00:00

I ask this question because when a loop is debugged with repeated print statements,

  • 0

I ask this question because when a loop is debugged with repeated print statements, it slows down the program much more that I would have originally expected. I have gotten used to this, but now I am curious as to the technical reasons why this would be the case? It seems to me that the various calculations and assignings of variables would be more expensive than outputting strings.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:12:04+00:00Added an answer on June 2, 2026 at 9:12 pm

    Quite a few, but another important (or even the most important) bottleneck is unrelated to the CPU: I/O overhead. Once the bytecode instruction(s) have been dispatched and all arguments have been converted to strings, a function is called to write those strings to sys.stdout. Depending on your system and how you run the program, this may be:

    1. A file on disk
    2. A pipe from a terminal emulator
    3. Some Python objects that capture the output (this is what IDLE does IIRC) to do who-knows-what with it (capture it, put it into a GUI, etc).

    In case #1, disk I/O is involved and that’s easily an order of magnitude slower than writing to RAM. And RAM is already awfully slow compared to today’s CPUs. As noted in a comment, this is less of an issue due to extensive buffering by the OS and by Python, but still takes time to issue the write and (depending on implementation details I don’t know much about) it may still take some time if someone flushes any buffers prematurely.

    In case #2, everything remains in memory, but it’s still a system call, some copying, and the other end has to read it and do something with it for you to notice (e.g. render it in a fancy terminal emulator with an anti-aliased font, which is a complex task itself). Less of an issue as it can happen concurrently, but it nevertheless places load on the CPU.

    In case #3, all bets are off. It may hash the output with bcrypt and send it to the moon for all we know. Do you happen to use IDLE? I recall a complaint that IDLE was (is?) very slow with redirecting output, especially with lots of tine pieces. It has to capture the output, concatenate it with the output so far, and let Tkinter render that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ask this question because i learned that in programming and designing, you must
I ask this question because it appears that viewDidLoad gets called before the main
I only ask this question because I have isolated it to pretty much three
I ask this question because I'm not able to test it at the moment.
I have to ask this question because I'm stuck, and I think its because
I'm not sure StackOverflow is the right place to ask this question, because this
This question is mostly academic. I ask out of curiosity, not because this poses
I ask this question because I've implemented a javascript solution to nested inlines (it
I am hesitated to ask this question because it looks weird. But anyway. Just
I'm hesitant to ask this question because of the vagueness of the situation, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.