Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.024 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'value,': 0.04; 'version?': 0.07; 'exceeds': 0.09; 'values,': 0.09; 'pm,': 0.10; 'this:': 0.10; 'wrote:': 0.14; 'lambda': 0.16; 'cc:addr:python-list': 0.17; 'cheers,': 0.19; 'header:In-Reply-To:1': 0.21; "haven't": 0.22; 'thu,': 0.22; 'maybe': 0.23; 'trying': 0.23; 'received:209.85.161.46': 0.23; 'received:mail- fx0-f46.google.com': 0.23; 'index': 0.25; 'parameters': 0.26; 'definition': 0.26; 'received:209.85.161': 0.26; 'message- id:@mail.gmail.com': 0.28; 'problem': 0.28; 'version,': 0.29; 'subject:?': 0.29; 'version': 0.29; 'all,': 0.30; 'cc:addr:python.org': 0.30; 'second': 0.30; 'cc:addr:gmail.com': 0.30; 'confused': 0.30; 'question': 0.34; 'all.': 0.35; 'version.': 0.35; 'usual': 0.35; 'cc:2**1': 0.35; 'received:google.com': 0.37; 'received:209.85': 0.37; 'skip:e 20': 0.37; 'could': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'should': 0.39; 'received:209': 0.39; 'map': 0.39; 'skip:z 10': 0.40; 'addition': 0.60; 'your': 0.60; 'total': 0.61; 'maximum': 0.62; 'increase': 0.64; 'subject:this': 0.76; 'delaney': 0.84; 'subject:Why': 0.84; 'summing': 0.84; 'subject:much': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=v9SVRL3eExnRC999GqK0PqO1jGygawMB6c/2tEuLuv4=; b=sjSNj+aA9o5M0SwsjdHSQb7f2GAvfKWCOcJNC8YTnGM9o8SHRUtywUHPft08ZBqdAm I4kDcafwe/E+DwGMnPYdJJTZpHwBHZjW7t4aE6QPD2Mkqb5cFt6ZajkGhv3Uh5LQpcoN y/dsfntkfoNAR7B9hds4v+balfiuz+PgTmXsM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=rAA4B+iesflxTuU0TRuGtW3WvGA3/5j86xxoNWt6vwNGxngvhNDqYWp4u+LB+9I3L7 CcvmT8rmnW6SYDmaMJssnVXaud9Y+2PwkvMq6IhB1RyvZPhZEzSVnVRTlbnFEMmALbAs tuo2//cXtV+PX0L+2P/7vuzhKPOk071ZF2fnc= MIME-Version: 1.0 In-Reply-To: References: <8bccb0f0-4c1a-4ec8-91b4-4f420d0d8eb9@glegroupsg2000goo.googlegroups.com> From: Ian Kelly Date: Thu, 2 Jun 2011 17:50:16 -0600 Subject: Re: Why is this so much faster? To: keirrice@gmail.com Content-Type: text/plain; charset=ISO-8859-1 Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307058647 news.xs4all.nl 49183 [::ffff:82.94.164.166]:46488 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6899 On Thu, Jun 2, 2011 at 4:38 PM, Tim Delaney wrote: > First of all, do you have the parameters to the lambda the wrong way around > in the map() version? zip(histogram, range(255)) will return (histogram > value, index), but enumerate(histogram) will return (index, histogram > value). But the parameters haven't been swapped, resulting in the histogram > value being squared in the map version, but the index being squared in the > manual summing version. Depending on the values, this could result in a > large performance increase in the second version (if the total value exceeds > the maximum size of your platform's "long" type). In addition to what Tim said, I question whether you should even be multiplying by the index at all. The usual definition of "root mean square" is this: math.sqrt(sum(x * x for x in values) / len(values)) I don't know the problem that you're trying to solve, though, so maybe I am just being confused by your terminology. Cheers, Ian