Re: $100 Contest Question

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hello all,

Talking about speed!

I found a much better way to implement my Hash table (below) for the 
"words.txt" file so I thought Id post this old piece.

-- hashing the dictionary takes @3.5 sec on my 233mhz laptop
-- 26 x 26 In alphabetical and length of text order.

The routine here is pretty fast, believe it or not I figured out a way to speed
this up 100 fold and still have the same accuracy and distribution.
I'll share that one in a month or so...

Maybe I could get some people to tell me how fast a PIII 550 or higher
might run this piece.

<snip.....>

without type_check
without trace

include get.e
include file.e
include print.e

atom t, junk
     t = time()

integer fnA, len
fnA = open("words.txt","r")

integer len_text
function EumsHash( sequence text) -- a more unique hash 
    atom h, g 
    integer short
    h = 0
    len = length(text)
    for i = 1 to len do 
        short = text[i]
        if short = 32 or short = 10 then
           len_text = i - 1
           exit
        end if
        if h > #0FFFFFFF or h < 0 then -- (overflow)
           h = and_bits(h, #0FFFFFFF)
        end if
        h *= 16
        h += short
        g = and_bits(floor(h / #1000000), #F0)
        if g != 0 then
           h = xor_bits(h, g)
        end if
        h = and_bits(h, not_bits(g))
    end for
    return h
end function

sequence hash_table
hash_table = repeat(repeat({}, 26),26) -- 26 -> 676 buckets

object line
integer letter
atom hashed

while 1 do -- hashing the dictionary takes @3.5 sec on my 233mhz laptop
    line = gets(fnA)
    if atom(line) then
       exit   
    end if
    hashed = EumsHash(line)
    hash_table[line[1] - 64][len_text] &= hashed
end while

close(fnA)

? time() - t

if getc(0) then
end if

<snip>


Later yall.

Euman
euman at bellsouth.net

----- Original Message ----- 
From: "Ray Smith" <smithr at ix.net.au>
To: "EUforum" <EUforum at topica.com>

> Derek Parnell wrote:
> 
> > Okay, so I took the bait. I've now got it down from 4.33 seconds to 1.7
> > seconds for that 4,267,462 byte file.
> 
> DAMN!
> 
> I can only get 2.8 seconds.
> I'll have to wait a whole month to see how u did it!
> 
> Ray Smith
> http://rays-web.com
> 
> P.S. Is it possible your PIII 550 is faster than my PIII 650???
> P.S.S I can't hope can't I!

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu