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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:53:35+00:00 2026-06-18T08:53:35+00:00

I made a little function using timeit just so I could be lazy and

  • 0

I made a little function using timeit just so I could be lazy and do less typing which isn’t panning out as planned.

The (relevant) code:

def timing(function, retries=10000, formatSeconds=3, repeat=10):
    """Test how long a function takes to run. Defaults are set to run
    10 times of 10000 tries each. Will display time as 1 of 4 types.
    0 = Seconds, 1 = milliseconds, 2= microseconds and 3 = nanoseconds.
    Pass in paramaters as: (function, retries=10000,formatSeconds=3, repeat=10)"""
    t = timeit.Timer(lambda: function)
    result = t.repeat(repeat=repeat,number=retries)
    rlist = [i/retries for i in result]

It runs fine but it keeps returning:

timeprofile.timing(find_boundaries(numpy.asarray(Image.open(
r'D:\Python\image\image4.jpg')),79))
    10 runs of 10000 cycles each: 
    Best time: 137.94764   Worst:158.16651  Avg: 143.25466 nanosecs/pass

Now, if I do from the interpreter:

import timeit
from timeit import Timer
t = timeit.Timer(lambda: (find_boundaries(numpy.asarray(Image.open(r'D:\Python\image\image4.jpg')),79)))
result = t.repeat(repeat=5,number=100)
result = [i/100 for i in result]

I end up with [0.007723014775432375, 0.007615270149786965, 0.0075242365377505395,
0.007420834966038683, 0.0074086862470653615]
, or about 8 milliseconds.

And if I run the profiler on the script, it also gives approximately the same result of about 8 milliseconds.

I’m not really sure what the problem is although I reckon it has something to do with the how it’s calling the function. When I check the data in the debugger it shows the function as a dictionary with a len of 53, and each key contains 1 to 15 tuples with a pair of 2-3 digit numbers in each.

So, if anyone knows why it’s doing that and would like to explain it to me, and how to fix it, that’d be great!

  • 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-18T08:53:37+00:00Added an answer on June 18, 2026 at 8:53 am

    Yes, there is a difference. When you run:

    timeprofile.timing(find_boundaries(numpy.asarray(Image.open(
        r'D:\Python\image\image4.jpg')),79))
    

    You are not passing in a function reference. You are calling the function and instead are passing in the result of that call. You are timing staticresult instead of somefunction(with, arguments).

    Move out the lambda:

    timeprofile.timing(lambda: (find_boundaries(numpy.asarray(Image.open(
        r'D:\Python\image\image4.jpg')),79)))
    

    This means you need to remove it from your timing function, and instead pass the function straight to the Timer() class:

    t = timeit.Timer(function)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using AngularJS and I have a little question here. I just made my
I made this little function from code snippets around the net. It does what
I have made a YUI module a little like the code shown below, which
i've made some little widget-plugins which are getting applied to eg. a textbox like
I've just started learning Objective-C and made a little compass app that will display
I made a little PHP script that checks if an email is valid. The
I made some little programs with Swing-components in JRuby. Now I want to convert
I made a little Shooter game with two ships firing at each other. I
I've made a little inline editor with some clean up logic. So if you
I've made a little forum and I want parse the date on newest posts

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.