Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'memory.': 0.07; 'assuming': 0.09; 'spaces': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; '10:00': 0.16; 'bit.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'separated': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'bit': 0.19; 'file,': 0.19; 'slightly': 0.19; 'split': 0.19; 'feb': 0.22; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'bytes': 0.24; 'tend': 0.24; 'cc:2**0': 0.24; 'long,': 0.26; 'header:In-Reply-To:1': 0.27; 'fixed': 0.29; 'words': 0.29; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'subject:size': 0.31; 'file': 0.32; 'probably': 0.32; 'quite': 0.32; 'guess': 0.33; "i'd": 0.34; 'but': 0.35; 'received:google.com': 0.35; 'words,': 0.36; 'list,': 0.38; 'pm,': 0.38; 'rather': 0.38; 'letters': 0.60; "you'll": 0.62; 'more': 0.64; '2-3': 0.68; '2014,': 0.84; 'short,': 0.84; 'to:none': 0.92; 'average': 0.93 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; bh=qRbXu9DdpTQ+5r0aQztmaSgOiNAvczv6nVZ9zzfzJvg=; b=aJkoXy9BY5vH0S3KH6mbxMuyYxcv8baYCpyCzi87NqOQgxpOCSrvKhkDeWQ5wCI1aI ft2PJfBDw0nB9UTuDswoDdXwxHHxayzfP+5RlBOcltOGfveQTNjZeu8kiG3yQwDQ+AFZ sX9hvXeKEIBz+zJrMbrs2rL/MqyevOFGiFNZFRx0jFWwY24AxESf4OtUomfWHlLx+DmQ 52CrPFVKZtbnSHRRikggHGJK7kzTwoQ6xuoRisW4GkBc6PsKrYpFUmyne+tu7e7T6UQB eimlbkaggHsMKFTgGYoi76xMDKdH9eMUAVPkYDQUDuqreTkv248XWdtTs7P+RE4o4AyN gWTQ== MIME-Version: 1.0 X-Received: by 10.66.102.39 with SMTP id fl7mr1130908pab.43.1391600687699; Wed, 05 Feb 2014 03:44:47 -0800 (PST) In-Reply-To: <52f219c5$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <7e7d3200-a4ae-4842-ad8d-68b4435b9006@googlegroups.com> <52f219c5$0$29972$c3e8da3$5496439d@news.astraweb.com> Date: Wed, 5 Feb 2014 22:44:47 +1100 Subject: Re: Finding size of Variable From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391600696 news.xs4all.nl 2902 [2001:888:2000:d::a6]:53604 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65475 On Wed, Feb 5, 2014 at 10:00 PM, Steven D'Aprano wrote: >> where stopWords.txt is a file of size 4KB > > My guess is that if you split a 4K file into words, then put the words > into a list, you'll probably end up with 6-8K in memory. I'd guess rather more; Python strings have a fair bit of fixed overhead, so with a whole lot of small strings, it will get more costly. >>> sys.version '3.4.0b2 (v3.4.0b2:ba32913eb13e, Jan 5 2014, 16:23:43) [MSC v.1600 32 bit (Intel)]' >>> sys.getsizeof("asdf") 29 "Stop words" tend to be short, rather than long, words, so I'd look at an average of 2-3 letters per word. Assuming they're separated by spaces or newlines, that means there'll be roughly a thousand of them in the file, for about 25K of overhead. A bit less if the words are longer, but still quite a bit. (Byte strings have slightly less overhead, 17 bytes apiece, but still quite a bit.) ChrisA