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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:15:45+00:00 2026-05-16T06:15:45+00:00

I am currently in a personal learning project where I read in an XML

  • 0

I am currently in a personal learning project where I read in an XML database. I find myself writing functions that gather data and I’m not sure what would be a fast way to return them.

Which is generally faster:

  1. yields, or
  2. several append()s within the function then return the ensuing list?

I would be happy to know in what situations where yields would be faster than append()s or vice-versa.

  • 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-16T06:15:45+00:00Added an answer on May 16, 2026 at 6:15 am

    yield has the huge advantage of being lazy and speed is usually not the best reason to use it. But if it works in your context, then there is no reason not to use it:

    # yield_vs_append.py
    data = range(1000)
    
    def yielding():
        def yielder():
            for d in data:
                yield d
        return list(yielder())
    
    def appending():
        lst = []
        for d in data:
            lst.append(d)
        return lst
    

    This is the result:

    python2.7 -m timeit -s "from yield_vs_append import yielding,appending" "yielding()"
    10000 loops, best of 3: 80.1 usec per loop
    
    python2.7 -m timeit -s "from yield_vs_append import yielding,appending" "appending()"
    10000 loops, best of 3: 130 usec per loop
    

    At least in this very simple test, yield is faster than append.

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

Sidebar

Related Questions

I have a personal learning project that I shelved for awhile but recently decided
I am writing a small program for my personal use to practice learning C++
I am currently creating my first app for a personal project and I'm having
I'm currently assessing a project where highly sensitive personal information is handled thus it
I'm starting a new personal Prism 4 project. The Reference Implementation currently uses Unity.
I'm currently trying to build a personal website to create a presence on the
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
Currently we have a project with a standard subversion repository layout of: ./trunk ./branches
Currently, I am writing up a bit of a product-based CMS as my first
Currently I know of only two ways to cache data (I use PHP but

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.