Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.067 X-Spam-Evidence: '*H*': 0.87; '*S*': 0.00; 'exec': 0.09; 'imply': 0.09; 'python': 0.11; '->': 0.16; '10000000': 0.16; 'subject:skip:e 10': 0.16; 'creating': 0.23; "i've": 0.25; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; '100000': 0.31; 'maybe': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'executing': 0.36; 'done': 0.36; 'hi,': 0.36; 'should': 0.36; 'seconds': 0.37; 'performance': 0.37; 'skip:& 10': 0.38; 'to:addr:python-list': 0.38; 'expect': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'such': 0.63; 'more': 0.64; 'works)': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=hyN1hYlujyt6lUFzeW2EW6CWgvJSqCitATHDbd4z6Kg=; b=l0lGWqIOyeW+bZnVUWHa+7KK5CDCT5cJ//2JT7e8nQoHjB9tlhH7timAVfiA/0Lp41 qDCwe0mQNuORqj7+h0ffQjaAIiHYYwZzhO7NnVi/iqsHVfo6ezq4mW3AauTsDRpfPBNw Ax3TmgLXVGkQHVLK3CVWVJKD1w3r6OakgGKSro+8Vb3MNsyLH4IfhcbwFhQFJqDmqiCU UAy0XrjPCkMn8QDXpHj+ju4uivGHxBGO7Iu5+9l6YzOjrHiBUrteb8NcThtztverEJD6 ddNEKqBjvEC/Ksy2VyVTA+Stgc8i1MzQAoWFydfpa38n2W7SpHSUr6YukZXVBx29VhLB IySw== MIME-Version: 1.0 X-Received: by 10.194.88.131 with SMTP id bg3mr42135504wjb.99.1421168537257; Tue, 13 Jan 2015 09:02:17 -0800 (PST) Date: Tue, 13 Jan 2015 18:02:17 +0100 Subject: Performance in exec environnements From: Jean-Baptiste Braun To: python-list@python.org Content-Type: multipart/alternative; boundary=089e010d849ed44b33050c8b95f7 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1421168544 news.xs4all.nl 2870 [2001:888:2000:d::a6]:35179 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83706 --089e010d849ed44b33050c8b95f7 Content-Type: text/plain; charset=UTF-8 Hi, I'm working on auto-generated python code with the exec function. I've done some performance benches : % python -m timeit '1 + 1' 10000000 loops, best of 3: 0.0229 usec per loop % python -m timeit "exec('1 + 1')" 100000 loops, best of 3: 11.6 usec per loop -> Maybe creating an exec environnement (I don't know how it works) takes time. But : % python -m timeit "1 + 1; 1 + 1" 10000000 loops, best of 3: 0.042 usec per loop % python -m timeit "exec('1 + 1; 1 + 1')" 100000 loops, best of 3: 15.7 usec per loop -> As if executing one more 1 + 1 would take 4 more seconds (100000 iterations) in an exec environnement. Am I missing something or should I expect that result ? What does using exec imply that causes such a difference ? Jean-Baptiste Braun --089e010d849ed44b33050c8b95f7 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

I'm working = on auto-generated python code with the exec function. I've done some pe= rformance benches :

% python -m timeit '1 + 1'
10000000 l= oops, best of 3: 0.0229 usec per loop

% python -m timeit "exec(= '1 + 1')"=C2=A0
100000 loops, best of 3: 11.6 usec per loo= p

-> Maybe creating an exec environnement (I don't know= how it works) takes time. But :

% python -m timeit "1 + 1; 1 += 1"=C2=A0=C2=A0
10000000 loops, best of 3: 0.042 usec per loop
=
% python -m timeit "exec('1 + 1; 1 + 1')"
100000 l= oops, best of 3: 15.7 usec per loop

-> As if executing one = more 1 + 1 would take 4 more seconds (100000 iterations) in an exec environ= nement.

Am I missing something or should I expect that result = ? What does using exec imply that causes such a difference ?

J= ean-Baptiste Braun
--089e010d849ed44b33050c8b95f7--