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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:23:02+00:00 2026-06-06T02:23:02+00:00

function_to_test(test, mylist): #test as an int, mylist as a list of int do_something return

  • 0
function_to_test(test, mylist): #test as an int, mylist as a list of int
     do_something    
     return something

function_generates_a_list(min, max): #min, max are int
     do_something
     return a_List

I need to timeit the function_to_test and only this one. The purpose is to test code in order to determine which one is the best to test if a int is in a list of int. (test is a googolplex and mylist is a huge list starting from min to max). Yes, I already know the result of the function, I need to know how many times it will cost.

My problem is: which syntax have I to use with timeit if I want to pass a global list as a local parameter of a function I test?

  • 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-06T02:23:04+00:00Added an answer on June 6, 2026 at 2:23 am

    The easiest way to do this is to create a function that takes no arguments, and calls your function with whatever arguments it needs:

    mylist = function_generates_a_list()
    def newfunc():
       function_to_test(mylist)
    

    You can then call timeit(newfunc). You could also do this with a lambda expression – timeit(lambda: function_to_test(mylist)) is exactly equivalent to the above. If you’re using timeit module-wise (ie, doing python -m timeit ...), you could also do this:

    python -m timeit --setup='import mymodule' 'mymodule.newfunc()'
    

    You could avoid having newfunc altogether by having a sufficiently convoluted setup string (the call to function_generates_a_list has to be in setup, possibly (as here) but not necessarily by happening when you import the module, if you don’t want it to be part of your timings), but having the function makes things more flexible and less annoying.

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

Sidebar

Related Questions

Take a look at the following program: class Test { List<int> myList = new
I have a List like test, bla, something, else But when I use the
I wanted to test how C++ behaves when the return value of a function
I have a function that return [[]] , and I want to test the
I'm writing an upload function for ColdFusion of Wheels and need to unit test
I wrote a test function to test my understanding of return-from in Lisp (defun
Is there a trick or a prelude function to test if a list contains
heres my test in java public class person { public String name; public int
i need to get the closest class html from my list, but its always
I need to apply a jQuery.click to the first level items only. How do

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.