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


Groups > comp.lang.python > #80835

Re:Strange result with timeit execution time measurment

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'skip:[ 20': 0.04; 'deemed': 0.09; 'explanation': 0.09; 'logic': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sure,': 0.09; 'thx': 0.09; 'def': 0.12; 'wrote': 0.14; 'isnt': 0.16; 'received:80.91.229.3': 0.16; 'received:97': 0.16; 'received:plane.gmane.org': 0.16; 'library': 0.18; 'module': 0.19; 'import': 0.22; 'comparing': 0.24; 'processor': 0.24; 'test.': 0.24; 'math': 0.24; 'looks': 0.24; 'compare': 0.26; 'header:X -Complaints-To:1': 0.27; 'function': 0.29; 'code': 0.31; '>>>>': 0.31; 'helpful.': 0.31; 'probably': 0.32; 'subject:time': 0.33; 'there,': 0.34; 'could': 0.34; 'subject:with': 0.35; 'but': 0.35; 'skip:- 20': 0.37; 'needed': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'skip:t 30': 0.61; 'simple': 0.61; 'optimized': 0.68; 'genuine': 0.78; 'different.': 0.84; 'faster.': 0.84; 'processor.': 0.84; 'sinus': 0.84; 'trig': 0.84; 'subject::': 0.85
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re:Strange result with timeit execution time measurment
Date Sat, 15 Nov 2014 13:08:28 -0500 (EST)
Organization news.gmane.org
References <54678857$0$2325$426a74cc@news.free.fr>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 97.73.240.77
X-Newsreader PiaoHong.Usenet.Client.VIP:1.65
X-Archive encrypt
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.15855.1416075286.18130.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416075286 news.xs4all.nl 2892 [2001:888:2000:d::a6]:49926
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80835

Show key headers only | View raw


"ast" <nomail@invalid.com> Wrote in message:
> Hi
> 
> I needed a function f(x) which looks like sinus(2pi.x) but faster.
> I wrote this one:
> 
> --------------------------
> from math import floor
> 
> def sinusLite(x):
>     x = x - floor(x)
>     return -16*(x-0.25)**2 + 1 if x < 0.5 else 16*(x-0.75)**2 - 1
> --------------------------
> 
> then i used module timeit to compare its execution time with math.sin()
> I put the sinusLite() function in a module named test.
> 
> then:
> 
>>>> import timeit
>>>> t1 = timeit.Timer("y=test.sinusLite(0.7)", "import test")
>>>> t2 = timeit.Timer("y=math.sin(4.39)", "import math")        ## 4.39 = 2*pi*0.7
> 
>>>>  t1.repeat(3, 1000000)
> [1.9994622221539373, 1.9020670224846867, 1.9191573230675942]
> 
>>>> t2.repeat(3, 1000000)
> [0.2913627989031511, 0.2755561810230347, 0.2755186762562971]
> 
> so the genuine sinus is much faster than my so simple sinLite() !
> Amazing isnt it ? Do you have an explanation ?
> 
> Thx
> 

Sure, the library function probably used the trig logic in the
 processor. 
Perhaps if you timed things on a processor without a
 "math coprocessor" things could be different.  But even there,
 you'd probably be comparing C to python. Library code is
 optimized where it's deemed helpful. 

-- 
DaveA

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


Thread

Strange result with timeit execution time measurment "ast" <nomail@invalid.com> - 2014-11-15 18:07 +0100
  Re: Strange result with timeit execution time measurment Peter Pearson <pkpearson@nowhere.invalid> - 2014-11-15 18:12 +0000
  Re:Strange result with timeit execution time measurment Dave Angel <davea@davea.name> - 2014-11-15 13:08 -0500
  Re: Strange result with timeit execution time measurment Peter Otten <__peter__@web.de> - 2014-11-15 18:59 +0100
  Re: Strange result with timeit execution time measurment Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-15 11:18 -0700

csiph-web