I would be interested to see the C routine.  J Forum msgs
do not seem to permit attachments, so you may have to
post the code in a J wiki page.

Since the J interpreter is written in C, in theory it should
be the case that a C function would be no slower than 
a J function.  In this particular case, I think the speed of J 
relative to C comes from

- Working with the entire file at once rather than byte-by-byte

- Well-crafted routines, in particular for E., that get to "see" 
large chunks of data at a time.  It's not necessarily that 
the J implementors are better C programmers than you, 
but that (probably) more effort had been spent in the
C functions in the J interpreter.

Some comments on your J function:

- better to use 6!:2 than 6!:1 for benchmarking (higher resolution)
- #x is the same as 0{$x

Finally, I am interested to know how much time it took you
to write the fully debugged J function vs. the fully debugged
C function.



----- Original Message -----
From: Robert Cyr <[EMAIL PROTECTED]>
Date: Thursday, October 2, 2008 9:59
Subject: [Jprogramming] performance : J or C ?
To: Programming forum <[email protected]>

> 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