Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43313

Re: performance of script to write very long lines of random chars

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.051
X-Spam-Evidence '*H*': 0.90; '*S*': 0.00; 'sufficient': 0.05; 'promising': 0.09; 'subject:script': 0.09; 'translation': 0.12; 'random': 0.14; '(note:': 0.16; 'charset,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:random': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'instance,': 0.24; 'header:In-Reply-To:1': 0.27; 'array': 0.29; 'character': 0.29; 'message-id:@mail.gmail.com': 0.30; 'idea,': 0.31; 'guess': 0.33; 'received:209.85': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'method': 0.36; 'received:209': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'generating': 0.39; 'to:addr:python.org': 0.39; 'skip:x 10': 0.40; 'skip:u 10': 0.60; 'full': 0.61; 'numbers': 0.61; 'profile': 0.61; 'first': 0.61; 'kind': 0.63; 'subject:long': 0.84; 'subject:very': 0.91; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=8HQ9nHLWtSd5Doo5RHVh+8na+1FfdMbXajw4dOhR1Z0=; b=0hdU2h6TgaA5PixVCXNhg2U8YAhdCw26p8SS/45GY5S9KGQQS7/V73Cqr/bTzGpTNP 6o0tyVQu3itPmGiPj7g22IbO7cXMkdnkUju4TciNwPwHDkykYlZcSD5tvmjjPp+/pPhq XY2Wkrhk3MVNoqvXqsaRA1XryrPSEaFLSkZv8izTugzsDw0StmyI1DDa5aDSqDVGaaUB pu+1RaZWOXl+UZ3Y49MntN/oAxmAzvxlW2HTwcaYZkNjONE1wm9u+XheAV3bST8dkZAZ oIh7Q4YQXeUsLQN9DxC4OJiKv3HdhzNgWQqf5vkTdEdA2ZEhjnUofHRFtGDPimpSdfM3 b9IQ==
MIME-Version 1.0
X-Received by 10.68.243.99 with SMTP id wx3mr6239048pbc.103.1365650077151; Wed, 10 Apr 2013 20:14:37 -0700 (PDT)
In-Reply-To <15b233c5-f961-479e-aec1-fe1467bd99d3@e8g2000yqg.googlegroups.com>
References <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> <mailman.435.1365645159.3114.python-list@python.org> <15b233c5-f961-479e-aec1-fe1467bd99d3@e8g2000yqg.googlegroups.com>
Date Thu, 11 Apr 2013 13:14:37 +1000
Subject Re: performance of script to write very long lines of random chars
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.437.1365650080.3114.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365650080 news.xs4all.nl 2615 [2001:888:2000:d::a6]:48438
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43313

Show key headers only | View raw


On Thu, Apr 11, 2013 at 12:40 PM, gry <georgeryoung@gmail.com> wrote:
> Appealing idea, but it's slower than the array solution: 5min 13
> secs.  vs 4min 30sec for the array:
>
> for l in range(rows):
>     for i in xrange(nchars):
>         stdout.write(random.choice(avail_chrs))
>     stdout.write('\n')
>
>
> os.urandom does look promising -- I have to have full control over the
> charset, but urandom is very fast at generating big random strings...
> stay tuned...

Without actually profiling it, my first guess would be that calling
random.choice() for every character is an optimization target. (NOTE:
Do profile it, if the urandom method isn't sufficient straight-off.)
You may want to consider, for instance, generating larger random
numbers and doing some kind of translation on them - which is
fundamentally what the urandom/b64encode method is doing.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

performance of script to write very long lines of random chars gry <georgeryoung@gmail.com> - 2013-04-10 18:21 -0700
  Re: performance of script to write very long lines of random chars Chris Angelico <rosuav@gmail.com> - 2013-04-11 11:45 +1000
    Re: performance of script to write very long lines of random chars Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-11 05:33 +0000
      Re: performance of script to write very long lines of random chars Chris Angelico <rosuav@gmail.com> - 2013-04-11 15:53 +1000
  Re: performance of script to write very long lines of random chars Michael Torrie <torriem@gmail.com> - 2013-04-10 19:52 -0600
    Re: performance of script to write very long lines of random chars gry <georgeryoung@gmail.com> - 2013-04-10 19:40 -0700
      Re: performance of script to write very long lines of random chars Chris Angelico <rosuav@gmail.com> - 2013-04-11 13:14 +1000
  Re: performance of script to write very long lines of random chars MRAB <python@mrabarnett.plus.com> - 2013-04-11 04:09 +0100
  Re: performance of script to write very long lines of random chars Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-11 07:47 +0000
    Re: performance of script to write very long lines of random chars Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-11 10:47 +0100
      Re: performance of script to write very long lines of random chars Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-11 10:50 +0000
        Re: performance of script to write very long lines of random chars Robert Kern <robert.kern@gmail.com> - 2013-04-11 16:49 +0530
        Re: performance of script to write very long lines of random chars Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-11 13:05 +0100
        Re: performance of script to write very long lines of random chars Robert Kern <robert.kern@gmail.com> - 2013-04-11 19:06 +0530
        Re: performance of script to write very long lines of random chars Chris Angelico <rosuav@gmail.com> - 2013-04-11 23:56 +1000
  Re: performance of script to write very long lines of random chars Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-11 10:47 +0100

csiph-web