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

Related Questions

Recently I've spotted a very disturbing issue. I've got the following python code: for
The following code: with open(J:\\python\\.data) as data: self.data=pickle.load(data) generated the following error: File J:\python\code.py,
I have the following code in python from selenium import webdriver from selenium.webdriver.common.by import
So I have the following code GAE code in python and it is a
I want to execute python code from C# with following code. static void Main(string[]
I was looking at the following code in python: for ob in [ob for
in the following python code: narg=len(sys.argv) print @length arg= , narg if narg ==
When running the following python code: >>> f = open(rmyfile.txt, a+) >>> f.seek(-1,2) >>>
I have the following Python code: cursor.execute("INSERT INTO table VALUES var1, var2, var3,") where
I tried running the following python code in Eclipse on Windows but it is

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.