Unexpected timing results with file I/O

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Mon Feb 4 19:44:28 CET 2008


On Mon, 04 Feb 2008 10:18:39 -0800, rdahlstrom wrote:

> On Feb 4, 1:12 pm, Carl Banks <pavlovevide... at gmail.com> wrote:
>> On Feb 4, 12:53 pm, rdahlstrom <roger.dahlst... at gmail.com> wrote:
>> > You have 500,000 people to fit through a door.  Here are your options:
>>
>> > 1.  For each person, open the door, walk through the door, then close
>> > the door.
>> > 2.  Open the door, allow everyone to walk through, then close the
>> > door.
>>
>> > Which one would you say would be a more efficient way to fit 500,000
>> > people through the door?
>>
>> Bad analogy.  A better analogy would be if each person has their own
>> door to walk through.
>
> The analogy holds.  It's faster to open the door, do what you need to
> do, then close the door than it is to open and close the door each
> time.

It doesn't hold.  Read the code again.  The total count of "open door" and
"close door" is the same in both cases.

It's

  for every person:
      open his door; push him through the door; close his door

vs.

  for every person:
      open his door
  for every person:
      push him through the door
  for every person:
      close his door

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list