# Index and Query (#54)

**URL:** <https://www.ruby-forum.com/t/index-and-query-54/48133>\
**Category:** Ruby\
**Created:** [November 15, 2005, 7:12am UTC](https://www.ruby-forum.com/t/index-and-query-54/48133 "2005-11-15T07:12:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@daniels](https://www.ruby-forum.com/u/daniels)\
**Post date:** [November 15, 2005, 7:12am UTC](https://www.ruby-forum.com/t/index-and-query-54/48133/1 "2005-11-15T07:12:40Z")

</div>

My solution is here:

[http://members.iinet.net.au/~soxbox/ruby\_quiz\_54/indexer.rb](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):

> **[iiNet Members Webspace End of Life | iiHelp](https://help.iinet.net.au/iinet-members-webspace-end-life)**
>
> The iiNet Members Webspace service has reached End of Life.

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.  
#####################################################################################
