From: Kent Dahl Date: 2002-09-24T03:58:45+09:00 Subject: Re: Speed up suggestions GOTO Kentaro wrote: > > 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: [...] > > 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"). I am confused. Ruby '\n' is not equivalent with Ruby "\n", so a difference would not be unexpected. (The size of the difference perhaps) In Python, "\n" and '\n' are the same and equivalent to Ruby "\n". It appears to me that the original comparision is null and void, since it does not do the same thing. Has anybody looked closer at the output of the Python vs the Ruby versions, like running a diff? It sure looks different to me... -- (\[ Kent Dahl ]/)_ _~_ __[ http://www.stud.ntnu.no/~kentda/ ]___/~ ))\_student_/(( \__d L b__/ NTNU - graduate engineering - 5. year ) ( \__\_�|�_/__/ ) _)Industrial economics and technological management( \____/_�_\____/ (____engineering.discipline_=_Computer::Technology___)