On Mon, Sep 23, 2002 at 11:44:30PM +0900, Vincent Foley wrote:
> Ruby: _wordList = open('/home/vince/fr_dict.txt', 'r').read.split('\n')
> Python: _wordList = (open('/home/vince/fr_dict.txt', 'r').read()).split('\n')
[...]
> ruby/crosswords.rb  1.52s user 0.13s system 68% cpu 2.407 total
[...]
> python/crossword.py  0.52s user 0.07s system 31% cpu 1.875 total

Yes, looks like python is faster than ruby, but it's possible to
speed-up both - python and ruby in your task, by using readlines
method. Take a look (i used /etc/termcap-BSD instead of your
fr_dict.txt) ;)

% cat py.py
blah = open('/etc/termcap-BSD', 'r').readlines()
% cat peigrek.py
blah = open('/etc/termcap-BSD', 'r').read().split('\n')
% cat rb.rb
blah = open('/etc/termcap-BSD', 'r').readlines
% cat ryby.rb
blah = open('/etc/termcap-BSD', 'r').read.split('\n')

So, I'm assuming that py.py and rb.rb should work faster than
peigrek.py and ryby.rb, because they're using readlines instead
of read and split methods. Let's take a look at the results:

% time python py.py; time python peigrek.py; time ruby rb.rb; time ruby ryby.rb
python py.py  0.23s user 0.05s system 132% cpu 0.212 total
python peigrek.py  0.23s user 0.06s system 127% cpu 0.227 total

py.py is faster than peigrek.py - good

ruby rb.rb  0.74s user 0.06s system 108% cpu 0.735 total
ruby ryby.rb  0.84s user 0.08s system 109% cpu 0.841 total

rb.rb is faster than ryby.rb

It's hard to ommit that python is much faster than ruby... :/

% time ruby rb.rb; time ruby ryby.rb; time python py.py; time python peigrek.py
ruby rb.rb  0.78s user 0.04s system 101% cpu 0.808 total
ruby ryby.rb  0.87s user 0.04s system 105% cpu 0.861 total

The same - rb.rb is faster than ryby.rb

python py.py  0.24s user 0.04s system 126% cpu 0.222 total
python peigrek.py  0.22s user 0.07s system 128% cpu 0.225 total

And same here.

So, we can speed both up, but even then python is much, much faster.. ;]

As I mentioned in another post (I sent it when a gateway news-mail_list 
was down so it's possible, that it get lost) ruby works faster
(than ruby ;)) with:

File.readlines('/etc/termcap-BSD')

Any ideas to speed it up even more ? :)

ps. anyway, hi, I'm quite new here, since I subsribed to the
    list yesterday ;)

-- 
[ Wojtek gminick Walczak ][ http://gminick.linuxsecurity.pl/ ]
[ gminick (at) hacker.pl ][ gminick (at) underground.org.pl/ ]