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


Groups > comp.lang.python > #41842

Re: Performance of int/long in Python 3

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <oscar.j.benjamin@gmail.com>
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; 'languages.': 0.04; 'syntax': 0.04; 'subject:Python': 0.06; 'matches': 0.07; 'integers': 0.09; 'width': 0.09; 'wrapper': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; '(actually': 0.16; 'behave': 0.16; 'cc:name:python list': 0.16; 'numpy': 0.16; 'rounding': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'truncation': 0.16; 'unsigned': 0.16; 'index': 0.16; 'wrote:': 0.18; 'module': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'issue,': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'class.': 0.26; 'this:': 0.26; 'subject:/': 0.26; 'signed': 0.27; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; '-0700,': 0.31; 'ctypes': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'there.': 0.32; 'style': 0.33; 'something': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'should': 0.36; 'rather': 0.38; 'skip:u 10': 0.60; 'march': 0.61; "you're": 0.61; 'complete': 0.62; 'skip:n 10': 0.64; 'mar': 0.68; 'ethan': 0.84; 'furman': 0.84; 'oscar': 0.84; 'presumably': 0.84; 'subject:long': 0.84; 'discovering': 0.91; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=nJihtTd2nv5o/bqwH7ieTlwZC0h2P8jPsaBQz1ef07o=; b=EG15FNUX47YUA+rK21kwEqUjMsHyCFXyh5jffi13xzO4lcYfJOuKQUMnfFmUzs6vBg N/syHGDb6Pv7986XeuTlMSFOwA2BeIG9t2XPPafNASrcSahuPKbJqPWe6xDbnQGQUlna F6/NcMDvbg6T5a7suHH9j4QkTdXEpNv2geJboequxVjuVHCWf3jUq8KfttghX1uT6mdZ IEcy1xlCzea6raEtKNZQKTCmXfv/HGsrujsBHbXTNnelB9vUh15uChS+HkiI8x5+I3Fz S7k4+GApnVhN0kZUxNOCNaZqeWJ8GR4w18Rjp242ImsC6TBwM1QwEz9Mf2fNbF9L9OxX JuLQ==
X-Received by 10.58.144.133 with SMTP id sm5mr18441603veb.23.1364259002953; Mon, 25 Mar 2013 17:50:02 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <5150e900$0$29998$c3e8da3$5496439d@news.astraweb.com>
References <CAPTjJmouUzXNr4Oq==LYB1UZ2UQb13Y6vTHGGzuzNXorNthjYg@mail.gmail.com> <mailman.3705.1364253727.2939.python-list@python.org> <5150e900$0$29998$c3e8da3$5496439d@news.astraweb.com>
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
Date Tue, 26 Mar 2013 00:49:42 +0000
Subject Re: Performance of int/long in Python 3
To "Steven D'Aprano" <steve+comp.lang.python@pearwood.info>
Content-Type text/plain; charset=ISO-8859-1
Cc Python List <python-list@python.org>
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.3709.1364259012.2939.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1364259012 news.xs4all.nl 6881 [2001:888:2000:d::a6]:52671
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41842

Show key headers only | View raw


On 26 March 2013 00:17, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> On Mon, 25 Mar 2013 16:16:05 -0700, Ethan Furman wrote:
>
[snip]
>> If you're working with
>> numbers, and speed is an issue, you really should be using one of the
>> numeric or scientific packages out there.
>
[snip]
> What I would like to see though is a module where I can import fixed-
> width signed and unsigned integers that behave like in C, complete with
> overflow, for writing code that matches the same behaviour as other
> languages.

Numpy can do this:

>>> import numpy
>>> a = numpy.array([0], numpy.uint32)
>>> a
array([0], dtype=uint32)
>>> a[0] = -1
>>> a
array([4294967295], dtype=uint32)

Unfortunately it doesn't work with numpy "scalars", so to use this
without the index syntax you'd need a wrapper class. Also it uses
Python style floor rounding rather than truncation as in C (actually I
seem to remember discovering that in C this is implementation
defined).

Presumably ctypes has something like this as well.


Oscar

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


Thread

Re: Performance of int/long in Python 3 Ethan Furman <ethan@stoneleaf.us> - 2013-03-25 16:16 -0700
  Re: Performance of int/long in Python 3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-26 00:17 +0000
    Re: Performance of int/long in Python 3 Chris Angelico <rosuav@gmail.com> - 2013-03-26 11:28 +1100
    Re: Performance of int/long in Python 3 Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-03-26 00:49 +0000
    Re: Performance of int/long in Python 3 Roy Smith <roy@panix.com> - 2013-03-25 20:55 -0400
      Re: Performance of int/long in Python 3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-26 05:01 +0000
        Re: Performance of int/long in Python 3 Chris Angelico <rosuav@gmail.com> - 2013-03-26 17:12 +1100
        Re: Performance of int/long in Python 3 Roy Smith <roy@panix.com> - 2013-03-26 09:18 -0400

csiph-web