Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'win32': 0.03; 'subject:Python': 0.06; 'function,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:skip:t 10': 0.09; 'windows,': 0.09; 'python': 0.11; 'wrote': 0.14; '0.03': 0.16; '0.04': 0.16; '2.7.3': 0.16; 'precision,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'seconds.': 0.16; 'there?': 0.16; 'unix,': 0.16; 'thanks,': 0.17; 'feb': 0.22; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'algorithms.': 0.24; 'processor': 0.24; 'script': 0.25; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'resolution': 0.29; 'skip:q 20': 0.31; 'case,': 0.35; 'definition': 0.35; 'but': 0.35; 'subject:?': 0.36; 'seconds': 0.37; 'wrong': 0.37; 'expressed': 0.37; 'depends': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'number,': 0.60; 'first': 0.61; 'more': 0.64; '2014,': 0.84; 'florian': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Florian Lindner Subject: time.perf_counter in Python 2? Date: Mon, 20 Oct 2014 09:47:42 +0200 Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Gmane-NNTP-Posting-Host: lapsgs09.informatik.uni-stuttgart.de User-Agent: KNode/4.14.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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413791277 news.xs4all.nl 2872 [2001:888:2000:d::a6]:59337 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79308 Hello, I wrote a script that does some time measurements. It uses time.perf_counter() from Python 3 which works very well. Now I need to backport it to python 2. Docs say that time.clock() is way to go: 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. On Windows, this function returns wall-clock seconds elapsed since the first call to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter(). The resolution is typically better than one microsecond. But for me it always returns the almost same number, nothing time like: Python 2.7.3 (default, Feb 27 2014, 19:58:35) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.clock() 0.03 >>> time.clock() 0.03 >>> time.clock() 0.04 >>> time.clock() 0.04 What's wrong there? Thanks, Florian