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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:45:32+00:00 2026-05-23T18:45:32+00:00

Question Which of these is the quickest? I’m using lighttpd’s mod_fastcgi , Python 2.7

  • 0

Question

Which of these is the quickest?

I’m using lighttpd’s mod_fastcgi, Python 2.7 and flup.server.fcgi.WSGIServer.

Should I yield strings directly in some_output_function, then return from app?

def app(env, start):
    start('200 OK', [('Content-Type', 'text/html')])
    return some_output_function()

def some_output_function():
    yield function_that_returns_a_string()
    yield 'yada yada'
    yield another_function_that_returns_a_string()

WSGIServer(app).run()

Should I return an array from some_output_function, then return from app?

def app(env, start):
    start('200 OK', [('Content-Type', 'text/html')])
    return some_output_function()

def some_output_function():
    out = []
    out.append(function_that_returns_a_string())
    out.append('yada yada')
    out.append(another_function_that_returns_a_string())
    return out

WSGIServer(app).run()

Should I yield a last-minute joined array from some_output_function, then return from app?

def app(env, start):
    start('200 OK', [('Content-Type', 'text/html')])
    return some_output_function()

def some_output_function():
    out = []
    out.append(function_that_returns_a_string())
    out.append('yada yada')
    out.append(another_function_that_returns_a_string())
    yield ''.join(out)

WSGIServer(app).run()

Should I return a last-minute joined array from some_output_function, then yield from app?

def app(env, start):
    start('200 OK', [('Content-Type', 'text/html')])
    yield some_output_function()

def some_output_function():
    out = []
    out.append(function_that_returns_a_string())
    out.append('yada yada')
    out.append(another_function_that_returns_a_string())
    return ''.join(out)

WSGIServer(app).run()

Test results

By creating a simple test application, with the output function having one function call, then sixteen ‘yada yada’ strings, then another function call as the output, I gathered some surprising average request times, using ApacheBench.

sudo ab -n10000 -c128 localhost/testapp/
  • 44 ms to yield strings directly in some_output_function, then return from app
  • 44 ms to return an array from some_output_function, then return from app
  • 30 ms to yield a last-minute joined array from some_output_function, then return from app
  • 30 ms to return a last-minute joined array from some_output_function, then yield from app

Even more interesting, is that when increasing the number of ‘yada yada’ output strings eight-fold, to 128 ‘yada yada’ output strings, these are the results:

  • 146 ms to yield strings directly in some_output_function, then return from app
  • 146 ms to return an array from some_output_function, then return from app
  • 30 ms to yield a last-minute joined array from some_output_function, then return from app
  • 30 ms to return a last-minute joined array from some_output_function, then yield from app

It appears that a common factor to save time is building a string array, then joining it just before exiting the inner output function, instead of yielding everywhere. Whether you yield inside and return outside, or return inside and yield inside, doesn’t appear to change anything.

So the only question now, really, is, should I yield inside or outside?

  • 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-23T18:45:33+00:00Added an answer on May 23, 2026 at 6:45 pm

    As a general rule generators are more efficient than lists when dealing with a lot of data. A list will be less overhead if the number of elements is small (e.g. in your example, only three elements).

    Whichever method you choose, it will most likely be dwarfed by the time spent fetching data from the cache or the datastore (dozens to hundreds of milliseconds). Shaving 10ms of response time is probably not worth worrying about.

    The reason why generators should be used is not for speed, but because large responses will be streamed to the client, which will use less memory and free up the server to process more requests. This is especially beneficial when done with an async server (e.g. gunicorn with eventlet workers, Tornado, etc.).

    To answer this question:

    So the only question now, really, is, should I yield inside or outside?

    Practically it should not make any difference.

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

Sidebar

Related Questions

There is a similar question on SO which suggests using NumberFormat which is what
Pretty simple question: which one of these two PHP (version 5+) header call is
Question: Which of these is the proper way to nest the <h1> and <article>
Inspired by Help understanding JQuery Attribute Equals Selector the question is: Which of these
As the question states - is there a good tool out there which lists
This question relates to those parts of the KenKen Latin Square puzzles which ask
(See question below for more context): Are there any situations in which <machineKey validationKey=AutoGenerate,IsolateApps
This question is related to another question which I asked yesterday! List all links
I know about this question: Which (third-party) debug visualizers for Visual Studio 2005/2008 do
This question relates to this question which I asked earlier this week. The answer

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.