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 953895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:07:29+00:00 2026-05-16T00:07:29+00:00

The following code in python takes very long to run. (I couldn’t wait until

  • 0

The following code in python takes very long to run. (I couldn’t wait until the program ended, though my friend told me for him it took 20 minutes.)

But the equivalent code in Java runs in approximately 8 seconds and in C it takes 45 seconds.

I expected Python to be slow but not this much, and in case of C which I expected to be faster than Java was actually slower. Is the JVM using some loop unrolling technique to achieve this speed? Is there any reason for Python being so slow?

import time
st=time.time()
for i in xrange(0,100000):
    for j in xrange(0,100000):
        continue;
print "Time taken : ",time.time()-st
  • 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-05-16T00:07:30+00:00Added an answer on May 16, 2026 at 12:07 am

    gcc 4.2 with the -O1 flag or higher optimize away the loop and the program takes 1 milli second to execute.
    This benchmark is not very representative as it is very far from any real world use.
    You’re doing a nested loop for a reason, and you never leave it empty.
    Python doesn’t optimize away the loop, although I see no technical reason why it couldn’t.

    Python is slower than C because it’s further from the machine language. xrange is a nice abstraction but it adds a heavy layer of machine code compared to a simple C loop.

    C source:

    int main( void ){
            int i, j;
            for (i=0;i<100000;i++){
                    for (j=0;j<100000;j++){
                            continue;
                    }
            }
            return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The AST can't give you that answer. Try using frame.f_lasti… May 16, 2026 at 11:33 pm
  • Editorial Team
    Editorial Team added an answer You'll probably want to override the onListItemClick method in your… May 16, 2026 at 11:33 pm
  • Editorial Team
    Editorial Team added an answer Use setInterval to set up a timed event: setInterval( function(){… May 16, 2026 at 11:33 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following code to run python and get the result in scratch
I'm very new to Python, sort of following Dive into Python 2 and wanted
I have the following code in Python using Numpy: p = np.diag(1.0 / np.array(x))
I use the following python code to download web pages from servers with gzip
I have the following Python code to remove files in a directory. For some
I'm very new to Python and multithreaded programming in general. Basically, I have a
Question How do you procedurally create a function in Python which takes specific named
I like being able to measure performance of the python functions I code, so
When I run this code on my computer with the help of Google App
So here's my problem. I have a python script that takes a zipfile and

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.