Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin1!goblin.stu.neva.ru!news.astraweb.com!border2.a.newsrouter.astraweb.com!news.tele.dk!news.tele.dk!small.news.tele.dk!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'programmer': 0.03; 'string.': 0.05; 'amounts': 0.07; 'string': 0.09; 'bytes,': 0.09; 'lawrence': 0.09; 'parsing': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'language.': 0.14; '3.3,': 0.16; 'cares': 0.16; 'make,': 0.16; 'utterly': 0.16; 'sat,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'file,': 0.19; 'thu,': 0.19; 'feb': 0.22; '>>>': 0.22; 'memory': 0.22; 'cc:addr:python.org': 0.22; 'bytes': 0.24; 'integer': 0.24; 'sorry,': 0.24; 'string,': 0.24; 'file.': 0.24; 'looks': 0.24; '---': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'developers': 0.25; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'character': 0.29; 'compared': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.31; 'easier': 0.31; '>>>>': 0.31; 'argue': 0.31; 'convenience': 0.31; "d'aprano": 0.31; 'purely': 0.31; 'really,': 0.31; 'reduced': 0.31; 'steven': 0.31; 'subject:size': 0.31; 'trivial': 0.31; 'yes.': 0.31; 'url:python': 0.33; 'core': 0.34; 'could': 0.34; 'agree': 0.35; 'except': 0.35; 'one,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'in:': 0.36; 'programming,': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'needed': 0.38; 'little': 0.38; 'short': 0.38; 'skip:& 20': 0.39; 'url:mail': 0.40; 'even': 0.60; 'free': 0.61; 'viruses': 0.61; 'course': 0.61; "you're": 0.61; 'you.': 0.62; 'save': 0.62; 'times': 0.62; 'protection': 0.63; 'our': 0.64; 'more': 0.64; 'antivirus': 0.68; 'lose': 0.68; 'nobody': 0.68; 'million': 0.74; 'savings': 0.81; 'complexity': 0.84; 'fifty': 0.84; 'safety.': 0.84; 'to:addr:yahoo.co.uk': 0.84; 'horror': 0.91; 'reducing': 0.93; '<>*': 0.95 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:to :cc:content-type; bh=sW9YaplkDvMmKaFkyBNd9XfY8Dshxh2YORmYB38+6Ck=; b=KKmJysOYY/gw24hYgIJgBglrGL16f9wxAu7QoJPGw0iWWsMJecPaETecANfRpd1+B+ 8PDqezAjvqHToG3UBjB5y/QeLDGviphllzI4uQGkTa9a03Nv7Vezxhs0PY7H2VODddiE FIsY9xwAiP3sx4lSGpAAA/bLQqRAdK99UJErKbE3Xze9sv0JKPMoGOMSOOOYMcqPR2Om c1XZFio40rdQLT9u5OcwaqQCOMZSR1JzVIjBeHnzTHRnO0aN7QW6zXPuEogEG6XRI/5p SUUf513Hnf0Rn/80bU4qfP6yz9y79siXpAWdC/IOkj8pbTLTcNj+WVe7hqYGg+d8BAqg Vo1A== MIME-Version: 1.0 X-Received: by 10.224.26.15 with SMTP id b15mr34416178qac.46.1391899550542; Sat, 08 Feb 2014 14:45:50 -0800 (PST) In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <7e7d3200-a4ae-4842-ad8d-68b4435b9006@googlegroups.com> <52f219c5$0$29972$c3e8da3$5496439d@news.astraweb.com> <888bd2fc-54b0-4c46-9d7b-d81d01a78b52@googlegroups.com> <52f59aeb$0$29972$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 8 Feb 2014 17:45:50 -0500 Subject: Re: Finding size of Variable From: David Hutto To: Mark Lawrence Content-Type: multipart/alternative; boundary=047d7bdc7ec245f05504f1ecdedc Cc: python-list 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: 216 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391899558 news.xs4all.nl 2891 [2001:888:2000:d::a6]:56513 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65695 --047d7bdc7ec245f05504f1ecdedc Content-Type: text/plain; charset=ISO-8859-1 On Sat, Feb 8, 2014 at 8:17 AM, Mark Lawrence wrote: > On 08/02/2014 02:48, Steven D'Aprano wrote: > >> On Thu, 06 Feb 2014 05:51:54 -0800, wxjmfauth wrote: >> >> Sorry, I'm only pointing you may lose memory when working with short >>> strings as it was explained. I really, very really, do not see what is >>> absurd or obsure in: >>> >>> sys.getsizeof('abc' + 'EURO') >>>>>> >>>>> 46 >>> >>>> sys.getsizeof(('abc' + 'EURO').encode('utf-32')) >>>>>> >>>>> 37 >>> >> >> >> Why do you care about NINE bytes? The least amount of memory in any PC >> that I know about is 500000000 bytes, more than fifty million times more. >> And you are whinging about wasting nine bytes? >> > One could argue that if you're parsing a particular file, a very large one, that those 9 bytes can go into the optimization of parsing aforementioned file. Of, course we have faster processors, so why care? Because it goes into the optimization of the code one is 'developing' in python. > >> If you care about that lousy nine bytes, Python is not the language for >> you. Go and program in C, where you can spent ten or twenty times longer >> programming, but save nine bytes in every string. >> >> Nobody cares about your memory "benchmark" except you. Python is not >> designed to save memory, Python is designed to use as much memory as >> needed to give the programmer an easier job. In C, I can store a single >> integer in a single byte. In Python, horror upon horrors, it takes 14 >> bytes!!! >> >> py> sys.getsizeof(1) >> 14 >> >> We consider it A GOOD THING that Python spends memory for programmer >> convenience and safety. Python looks for memory optimizations when it can >> save large amounts of memory, not utterly trivial amounts. So in a Python >> wide build, a ten-thousand block character string requires a little bit >> more than 40KB. In Python 3.3, that can be reduced to only 10KB for a >> purely Latin-1 string, or 20K for a string without any astral characters. >> That's the sort of memory savings that are worthwhile, reducing memory >> usage by 75%. >> >> Could Python save memory by using UTF-8? Yes. But it would cost >> complexity and time, strings would be even slower than they are now. That >> is not a trade-off that the core developers have chosen to make, and I >> agree with them. >> >> >> >> > This is a C +1 to save memory when compared against this Python +1 :) > > -- > My fellow Pythonistas, ask not what our language can do for you, ask what > you can do for our language. > > Mark Lawrence > > --- > This email is free from viruses and malware because avast! Antivirus > protection is active. > http://www.avast.com > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com * --047d7bdc7ec245f05504f1ecdedc Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Sat, Feb 8, 2014 at 8:17 AM, Mark Lawrence <= ;breamoreboy@y= ahoo.co.uk> wrote:
On 08/02/2014 02:48, Steven D'Aprano wro= te:
On Thu, 06 Feb 2014 05:51:54 -0800, wxjmfauth wrote:

Sorry, I'm only pointing you may lose memory when working with short strings as it was explained. I really, very really, do not see what is
absurd or obsure in:

sys.getsizeof('abc' + 'EURO')
46
sys.getsizeof(('abc' + 'EURO').encode('utf-32'))
37


Why do you care about NINE bytes? The least amount of memory in any PC
that I know about is 500000000 bytes, more than fifty million times more. And you are whinging about wasting nine bytes?

One could argue that if you're parsing a particula= r file, a very large one, that those 9 bytes can go into the optimization o= f parsing aforementioned file. Of, course we have faster processors, so why= care?

Because it goes into the optimization of the code one is 'developin= g' in python.
=A0

If you care about that lousy nine bytes, Python is not the language for
you. Go and program in C, where you can spent ten or twenty times longer programming, but save nine bytes in every string.

Nobody cares about your memory "benchmark" except you. Python is = not
designed to save memory, Python is designed to use as much memory as
needed to give the programmer an easier job. In C, I can store a single
integer in a single byte. In Python, horror upon horrors, it takes 14
bytes!!!

py> sys.getsizeof(1)
14

We consider it A GOOD THING that Python spends memory for programmer
convenience and safety. Python looks for memory optimizations when it can save large amounts of memory, not utterly trivial amounts. So in a Python wide build, a ten-thousand block character string requires a little bit
more than 40KB. In Python 3.3, that can be reduced to only 10KB for a
purely Latin-1 string, or 20K for a string without any astral characters. That's the sort of memory savings that are worthwhile, reducing memory<= br> usage by 75%.

Could Python save memory by using UTF-8? Yes. But it would cost
complexity and time, strings would be even slower than they are now. That is not a trade-off that the core developers have chosen to make, and I
agree with them.




This is a C +1 to save memory when compared against this Python +1 :)

--
My fellow Pythonistas, ask not what our language can do for you, ask what y= ou can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protec= tion is active.
http://www.avast.com=


--
https://mail.python.org/mailman/listinfo/python-list



--
Best Rega= rds,
David Hutto<= /span>
CEO: http://www.hitwebdevelopment.com
--047d7bdc7ec245f05504f1ecdedc--