Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: srinivas devaki Newsgroups: comp.lang.python Subject: Re: sobering observation, python vs. perl Date: Thu, 17 Mar 2016 21:18:43 +0530 Lines: 98 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de grLfFcUb3e+Ammen6gxZrA33mtGGH10ymM7aa0AAjhVg== Return-Path: 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; 'modified': 0.05; 'sys': 0.05; 'cc:addr:python-list': 0.09; '#print': 0.09; 'res': 0.09; 'python': 0.10; 'subject:python': 0.14; '+91': 0.15; 'file,': 0.15; 'thu,': 0.15; 'variables': 0.15; '2016': 0.16; 'doin': 0.16; 'line)': 0.16; 'line),': 0.16; 'match:': 0.16; 'perl.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'res:': 0.16; 'slow,': 0.16; 'wrote:': 0.16; 'student': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '%s"': 0.22; 'junior': 0.22; 'import': 0.24; 'header:In- Reply-To:1': 0.24; 'sort': 0.25; "i've": 0.25; 'skip:# 10': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'away.': 0.29; 'perl': 0.29; 'print': 0.30; 'that.': 0.30; 'url:mailman': 0.30; 'seconds': 0.31; 'generally': 0.32; 'skip:. 10': 0.32; 'url:python': 0.33; 'open': 0.33; 'url:listinfo': 0.34; 'file': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'too': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'indian': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'log': 0.38; 'url:mail': 0.40; 'some': 0.40; 'school': 0.62; 'real': 0.62; 'mar': 0.65; 'soon': 0.65; 'subject:. ': 0.67; 'smith': 0.76; '(3rd': 0.84; 'amazed': 0.84; 'ph:': 0.84; 'precompiled': 0.84; 'programs:': 0.84; 'numbers:': 0.91; 'improvement': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=KvtUWgloKjTewfdRFX3p6yJQgYoOC6/CGhK0PG9BLC8=; b=xOVyHIhTIvDn3AXMTtgAeZ1n89kWQbiMufp5KleBooCnmRUeGjpB1vZoUVl69rHcs0 wkS9BQ5V57K67kX/8e6Vgxl2CzpRvjyrFpheWpNTOxuNbvmUFoR4kV7/R8IaXVjkImlX L6szCTnfUgmtARpORGR4WhuJX8RGEkdfr17u9mOEwo/C5YfhwRaJBNkp2S49umS6tbuA C2zH8LXa0e/96HTtAM4ccKBNlH+kNjtqJJJOCoBhcC87awnwsxJ7Eu+d14h1gzLEusfc bqB61C2TKUPA2qBJ9XFRzm37RkNQVfbYpZo5I0P30QecesOq9vEqK74fMTdsdlATSov4 mSmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=KvtUWgloKjTewfdRFX3p6yJQgYoOC6/CGhK0PG9BLC8=; b=L8pkN6PEVK5Z1PdaWzPRLf+52js2Vf6i7GWnXeMVXU0QslzmLOT0rI8r9l36pmPLY1 en/pLSusPPgGnq9E/8732VIz0t81e0g+Bo2vy+6dqJZ8O6WKmmpW/fNiUJaS2lmK0USd PZVdTF52zlGnlx0pFG3fHsKabGDJza/nqgoroBgvPmAeDVwH7+GBvdm+Ly70y0yx8NlH SUuL9x/XYPU6XWkRouLtVCfy8WLzMbrNOSuElji6QqP5vNGVQ74sVvVz8WpQ4dhKX9fY Z11tPBZkXeeMDBnCUW6tzYgUUaAxJ3BETjDyVwBW+aoKaQHP6muUxgK2PmBGEjRSia4P mqwA== X-Gm-Message-State: AD7BkJIFx4JWAoVM/S2nKJ//vzednBHsrfIu2EJfY5unFiCitn4GHG6P6iKGs5R5fDs8OjwxO025XUE4qYzZNA== X-Received: by 10.50.160.9 with SMTP id xg9mr34921392igb.41.1458229762459; Thu, 17 Mar 2016 08:49:22 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105102 please upload the log file, and global variables in python are slow, so just keep all that in a function and try again. generally i get 20-30% time improvement by doin that. On Thu, Mar 17, 2016 at 8:59 PM, Charles T. Smith wrote: > I've really learned to love working with python, but it's too soon > to pack perl away. I was amazed at how long a simple file search took > so I ran some statistics: > > $ time python find-rel.py > ./find-relreq *.out | sort -u > TestCase_F_00_P > TestCase_F_00_S > TestCase_F_01_S > TestCase_F_02_M > > real 1m4.581s > user 1m4.412s > sys 0m0.140s > > > $ time python find-rel.py > # modified to use precompiled REs: > TestCase_F_00_P > TestCase_F_00_S > TestCase_F_01_S > TestCase_F_02_M > > real 0m29.337s > user 0m29.174s > sys 0m0.100s > > > $ time perl find-rel.pl > find-relreq.pl *.out | sort -u > TestCase_F_00_P > TestCase_F_00_S > TestCase_F_01_S > TestCase_F_02_M > > real 0m5.009s > user 0m4.932s > sys 0m0.072s > > Here's the programs: > > #!/usr/bin/env python > # vim: tw=0 > import sys > import re > > isready = re.compile ("(.*) is ready") > relreq = re.compile (".*release_req") > for fn in sys.argv[1:]: # logfile name > tn = None > with open (fn) as fd: > for line in fd: > #match = re.match ("(.*) is ready", line) > match = isready.match (line) > if match: > tn = match.group(1) > #match = re.match (".*release_req", line) > match = relreq.match (line) > if match: > #print "%s: %s" % (tn, line), > print tn > > vs. > > while (<>) { > if (/(.*) is ready/) { > $tn = $1; > } > elsif (/release_req/) { > print "$tn\n"; > } > } > > Look at those numbers: > 1 minute for python without precompiled REs > 1/2 minute with precompiled REs > 5 seconds with perl. > -- > https://mail.python.org/mailman/listinfo/python-list -- Regards Srinivas Devaki Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad) Computer Science and Engineering Department ph: +91 9491 383 249 telegram_id: @eightnoteight