Good afternoon all,

Having this seemingly well written routine in C,  I wrote it's equivalent in
J, wishing to estimate the penalty for using J.

I am amazed and a bit mystified to find  J nearly twice as fast: on this
Acer One with Gentoo Linux.


   - C test:                2.0  secs
   - J first test          1.13 secs
   - J second test:  0.71 secs

>From a 38 Meg file, find all diff rent IP addresses following a given
label.  In this test the number of addresses is about 16000, the required
different addresses is 7.

Attached is the C routine, and a 20K sample of the 38 meg data file.

Is the J use of mapped files the trick in favor of J?  In C the entire file
is scanned, byte by byte.*


J routine:*
 require'jmf'
   require'files dir'

find=: 4 : 0
NB.  x is the label preceding the IP adress,
NB. y is the file name
NB. produces a list of different IP adresses.
    deb=. 6!:1 ''
    JCHAR map_jmf_ 'file';y
    nos=. I. x E. file
    n=:(nos+/(0{$x)+i.16){file
    unmapall_jmf_ ''
    a=.'time in secs to read 38 megs, find IP adrs. etc. ',6j2":secs=. (6!:1
'')-deb
    a=.a,:'diffreent IP adresses'
    a,~.((n i."1 (' ')){."0 1 (n))
)

findTxt=: 3 : 0
NB. for testing find.
    fn=:'/media/KINGSTON/logParse/messages.2'
    NB.fn=:'G:\logParse\messages.2'
    txt =.' rhost='
    txt find fn
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to