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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:22:30+00:00 2026-06-08T09:22:30+00:00

Using timeit , I have a setup code block which sets up a data

  • 0

Using timeit, I have a setup code block which sets up a data structure filled with dummy data, and I have two statements (say, test1 and test2) which retrieve data from this data structure in different ways.

When I do

t = timeit.Timer(test1, setup)
print t.timeit(3000)
t = timeit.Timer(test2, setup)
print t.timeit(3000)

I notice that the setup is run twice, once for each test. Is it possible to make the two tests share the same setup, i.e. run setup code block exactly once and use the exactly the same data structure created for both tests?

  • 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-08T09:22:33+00:00Added an answer on June 8, 2026 at 9:22 am

    The easiest way to achieve this is to put the setup code into a module setup.py, and then use

    "from setup import name_1, name_2, name_3"
    

    as setup parameter to timeit.timeit(). (Note that wildcard imports won’t work correctly in that situation.)

    If you don’t want to use a separate module, put the code in the main module and use

    "from __main__ import name_1, name_2, name_3"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using .net framework 4.0 and working on Web deployment Setup, I have
So I have a block of PHP code, and I simply wanted to have
I have a method, which gets executed, say 20 times. My method has an
I have an ajax call for some data (using jQuery). after the user clicks
I'm drawing rectangles on the screen using the basic NSBezierPath method. I have an
Possible Duplicate: Run a code in given time interval I have a method that
We have a build machine running in our development department, which we've set up
I have a tree structure of widgets e.g. collection contains models and model contains
NHibernate is driving me 'Nuts'!!! I have the following mapping. Which returns this error
I have been using several Microbreaks software solutions. And all of them are overkill

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.