Index and Query (#54)

My solution is here:

http://members.iinet.net.au/~soxbox/ruby_quiz_54/indexer.rb

And also a script that benchmarks it against grepping the files manually
(My first attempts ended up being slower… eeep):

I used shakespeare’s sonnets from project gutenburg to do the testing.

Results:

                      user     system      total        real

first word 0.157000 0.047000 0.204000 ( 0.219000)
median word 0.109000 0.046000 0.155000 ( 0.156000)
last word 0.141000 0.063000 0.204000 ( 0.203000)
index last word 0.062000 0.000000 0.062000 ( 0.063000)
non-existant 0.063000 0.000000 0.063000 ( 0.062000)
grep first 1.656000 1.453000 3.109000 ( 3.625000)
grep median 1.969000 1.438000 3.407000 ( 3.438000)
grep last 2.343000 1.140000 3.483000 ( 4.125000)

And, if I take out the indexing of the word list file (which wont occur
if you use it from the commandline):

                      user     system      total        real

first word 0.562000 0.078000 0.640000 ( 0.687000)
median word 0.547000 0.047000 0.594000 ( 0.703000)
last word 0.547000 0.078000 0.625000 ( 1.000000)
index last word 0.469000 0.000000 0.469000 ( 0.500000)
non-existant 0.468000 0.031000 0.499000 ( 0.500000)
grep first 1.875000 1.219000 3.094000 ( 3.219000)
grep median 1.875000 1.250000 3.125000 ( 3.188000)
grep last 1.813000 1.344000 3.157000 ( 3.203000)

#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################