From: GOTO Kentaro Date: 2002-09-24T02:47:07+09:00 Subject: Re: Speed up suggestions At Mon, 23 Sep 2002 23:44:30 +0900, Vincent Foley wrote: > In my experience, Python is faster than Ruby. I made a small script to > help me do crossword puzzles. The first thing I do, is open a > dictionary file and put it in memory: > > Ruby: _wordList = open('/home/vince/fr_dict.txt', 'r').read.split('\n') > Python: _wordList = (open('/home/vince/fr_dict.txt', 'r').read()).split('\n') I tried a benchmark test with ruby 1.6.7: require "benchmark" a, b = 0, 0 Benchmark::bmbm do |x| x.report('\n'.inspect){a=open("/usr/share/dict/words").read.split('\n')} x.report("\n".inspect){b=open("/usr/share/dict/words").read.split("\n")} end p a.size p b.size produces Rehearsal ----------------------------------------- "\\n" 1.437500 0.046875 1.484375 ( 1.740030) "\n" 0.664062 0.054688 0.718750 ( 0.781546) -------------------------------- total: 2.203125sec user system total real "\\n" 2.671875 0.132812 2.804688 ( 3.055595) "\n" 0.281250 0.015625 0.296875 ( 0.303488) 235881 235881 This shows split('\n') takes about *ten* times total time than split("\n"). -- Gotoken