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


Groups > comp.lang.python > #79309

Re: time.perf_counter in Python 2?

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!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.029
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'subject:Python': 0.06; 'subject:skip:t 10': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; '2.7.3': 0.16; 'comparison.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'measured': 0.16; 'precision,': 0.16; 'runs,': 0.16; 'seconds.': 0.16; 'unix,': 0.16; 'wrote:': 0.18; "python's": 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'algorithms.': 0.24; 'processor': 0.24; 'fairly': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'see,': 0.30; 'waste': 0.30; 'message- id:@mail.gmail.com': 0.30; 'there.': 0.32; 'case,': 0.35; 'definition': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'subject:?': 0.36; 'expressed': 0.37; 'depends': 0.38; 'fact': 0.38; 'pm,': 0.38; 'number,': 0.60; "you're": 0.61; 'times': 0.62; "you'll": 0.62; 'more': 0.64; 'taking': 0.65; 'wall': 0.65; 'close': 0.67; 'mar': 0.68; '20,': 0.68; 'busy.': 0.68; 'user,': 0.69; '2014,': 0.84; 'florian': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=PTh+LesG7JtBFB4Nwaqaint+vxXN78qTEPL8hmGwFBk=; b=xV97f/3BKq1qxPdYX8+jncOKVpCnk2g/jQCXUsb1lKF4quZktHQKsjeNM1KrXrzCf8 b3e/c0AmdmTjkmX6QykrG0U/eu9iyo49h1QWgnc4ssE9xQeBjRShmNeAJ0HVI1xIjuBK AohtTC9PDJR0IEp2cQcyEnaYwkCP50ybueTIfDi27XccC/YweNPkpxkrUQZI2Q6W9htB V5QgAqqGxrvwB+IgWIvylnojimjTcqsEJeKsjClANUlXbt0zsZ2iXCGL5isufPK9iYVM ukF5z+7iKxUN98ynYYg1wqXef3rYWbm2qNIDLn2ijGtcaANchNiJ2pIcjCvbxynhWHi1 dBPg==
MIME-Version 1.0
X-Received by 10.50.43.130 with SMTP id w2mr16430219igl.34.1413791908466; Mon, 20 Oct 2014 00:58:28 -0700 (PDT)
In-Reply-To <m22emv$ki$1@ger.gmane.org>
References <m22emv$ki$1@ger.gmane.org>
Date Mon, 20 Oct 2014 18:58:28 +1100
Subject Re: time.perf_counter in Python 2?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14994.1413791917.18130.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1413791917 news.xs4all.nl 2948 [2001:888:2000:d::a6]:33993
X-Complaints-To abuse@xs4all.nl
X-Received-Body-CRC 1649688163
X-Received-Bytes 5144
Xref csiph.com comp.lang.python:79309

Show key headers only | View raw


On Mon, Oct 20, 2014 at 6:47 PM, Florian Lindner <mailinglists@xgm.de> wrote:
> time.clock()
> On Unix, return the current processor time as a floating point number
> expressed in seconds. The precision, and in fact the very definition of the
> meaning of “processor time”, depends on that of the C function of the same
> name, but in any case, this is the function to use for benchmarking Python
> or timing algorithms.
>
> But for me it always returns the almost same number, nothing time like:

You're doing practically no work in there. You're using almost no
processor time - the interpreter's waiting for the user, not actually
busy. If you create a busyloop, you'll see time.clock() go up roughly
linearly:

rosuav@sikorsky:~$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> def killtime():
...     start=time.time()
...     end=time.clock()+1
...     while time.clock()<end: pass
...     return time.time()-start
...
>>> killtime()
1.0048420429229736
>>> killtime()
1.004641056060791
>>> killtime()
1.0081689357757568
>>> killtime()
1.0019969940185547
>>> killtime()
1.0044770240783691

This function will do its best to waste one second of CPU time. As you
see, it's taking pretty much exactly one second of wall time to do so
(as measured by time.time()). At the end of a few of these runs,
time.clock() will return a value that's fairly close to 1.0 times the
number of executions of killtime(), as the other work Python's doing
is insignificant by comparison.

ChrisA

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


Thread

Re: time.perf_counter in Python 2? Chris Angelico <rosuav@gmail.com> - 2014-10-20 18:58 +1100

csiph-web