From: Tomas Brixi Date: 2002-09-21T01:22:34+09:00 Subject: Speed up suggestions --0-416087302-1032538949=:10000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, I have written just a simple script to analyze a log file and (just for fun) I have written exactly the same in python to see the difference and ... python is almost twice the faster doing the same job :-| (???) You can see attached files for sources. Environment: P4 1.8Ghz, 256MB, WinXP Pro. Python 2.2.1, Ruby 1.7.2-4 - the Pragmatic distribution. The analyzed file is about 420 Mbytes and python does it in about 60 sec and ruby in about 115 sec. Have some suggestion how to speed the ruby code? Regards Tom __________________________________________________ Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! http://sbc.yahoo.com --0-416087302-1032538949=:10000 Content-Type: text/plain; name="parse.py" Content-Description: parse.py Content-Disposition: inline; filename="parse.py" import re import string import time outf = file( "found.log", "w" ) r = re.compile( "xxx\\xxxxxxxx", re.I ) t = time.time() print time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime( t ) ) for line in file( "WEB.log" ): if string.find( line, "#" ) == 0: continue pom = string.split( line, "\t" ) if r.search( pom[1] ) != None: outf.write( line + "\n" ) te = time.time() print time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime( te ) ) print "Time: " + str( (te - t) ) outf.close() --0-416087302-1032538949=:10000 Content-Type: application/octet-stream; name="parse.rb" Content-Transfer-Encoding: base64 Content-Description: parse.rb Content-Disposition: attachment; filename="parse.rb" DQpvdXRmID0gRmlsZS5uZXcoICJmb3VuZC5sb2ciLCAidyIgKQ0KciA9IFJl Z2V4cC5uZXcoICJ4eHhcXHh4eHh4eHh4IiwgUmVnZXhwOjpJR05PUkVDQVNF ICkNCnQgPSBUaW1lLm5ldw0KcHV0cyB0DQpGaWxlLm5ldyggIldFQi5sb2ci ICkuZWFjaF9saW5lIGRvDQoJfGxpbmV8DQoJbmV4dCBpZiBsaW5lLmluZGV4 KCAiIyIgKSA9PSAwDQoJcG9tID0gbGluZS5zcGxpdCggIlx0IiApDQoJaWYg cG9tWzFdID1+IHINCgkJb3V0Zi53cml0ZSggbGluZSArICJcbiIgKQ0KCWVu ZA0KZW5kDQp0ZSA9IFRpbWUubmV3DQpwdXRzIHRlDQpwcmludCAiVGltZTog Ig0KcHV0cyAodGUgLSB0KS50b19zDQpvdXRmLmNsb3NlKCkNCg== --0-416087302-1032538949=:10000--