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

  • Home
  • SEARCH
  • 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 6111331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:37:06+00:00 2026-05-23T14:37:06+00:00

A quote from Python Programming: An Introduction to Computer Science We could have taken

  • 0

A quote from “Python Programming: An Introduction to Computer Science“

We could have taken the square root
using exponentiation **. Using
math.sqrt is somewhat more efficient.

“Somewhat”, but to what extent, and how?

  • 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-23T14:37:07+00:00Added an answer on May 23, 2026 at 2:37 pm

    Theoretically, hammar’s answer and duffymo’s answer are good guesses. But in practice, on my machine, it’s not more efficient:

    >>> import timeit
    >>> timeit.timeit(stmt='[n ** 0.5 for n in range(100)]', setup='import math', number=10000)
    0.15518403053283691
    >>> timeit.timeit(stmt='[math.sqrt(n) for n in range(100)]', setup='import math', number=10000)
    0.17707490921020508
    

    Part of the problem is the . operation. If you import sqrt directly into the namespace, you get a slight improvement.

    >>> timeit.timeit(stmt='[sqrt(n) for n in range(100)]', setup='from math import sqrt', number=10000)
    0.15312695503234863
    

    Key word there: slight.

    Further testing indicates that as the number gets larger, the benefit you get from using sqrt increases. But still not by a lot!

    >>> timeit.timeit(stmt='[n ** 0.5 for n in range(1000000)]', setup='import math', number=1)
    0.18888211250305176
    >>> timeit.timeit(stmt='[math.sqrt(n) for n in range(1000000)]', setup='import math', number=1)
    0.18425297737121582
    >>> timeit.timeit(stmt='[sqrt(n) for n in range(1000000)]', setup='from math import sqrt', number=1)
    0.1571958065032959
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have taken Problem #12 from Project Euler as a programming exercise and to
firstly, let me quote a bit an essay from Expert Python Programming book: In
For example, mysql quote table name using SELECT * FROM `table_name`; notice the `
i dont have any experience in python programming but I get to run python
I found the quoted text in Programming Python 3rd edition by Mark Lutz from
I'm new to Python (I have been programming in Java for multiple years now
Here is a quote from https://stackoverflow.com/users/893/greg-hewgill answer to Explain Python's slice notation . Python
Using Python 2.5.2 and Linux Debian, I'm trying to get the content from a
I'm a newbie to programming. I had 1 semester of computer science (we used
From http://code.google.com/p/unladen-swallow/wiki/ProjectPlan I quote: Using a JIT will also allow us to move Python

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.