CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
exists() / grep too slow ?

 



amphetamine
stranger

Jul 19, 2001, 12:05 PM

Post #1 of 4 (1025 views)
exists() / grep too slow ? Can't Post

I wrote a little bot and use the NET::IRC module
short description of the code: everytime someone sends a priv msg to the bot = $arg, the bot should check if the msg was sent before (of another user,etc.), so i safe the last 10
msgs in a hash/array (wrote 2 different solutions) to check the new msg if they exist in the hash/array, if not the programm deletes the "oldest" element and makes a new one with the new msg in $arg.

the problem is, it takes too much time for checking the msgs, between the msgs can be get very long sometimes !!






amphetamine
stranger

Jul 19, 2001, 11:12 PM

Post #2 of 4 (1013 views)
Re: exists() / grep too slow ? [In reply to] Can't Post

you can get the code at
http://members.chello.at/hirter/perl.pl



mhx
Enthusiast / Moderator

Jul 20, 2001, 1:24 AM

Post #3 of 4 (1008 views)
Re: exists() / grep too slow ? [In reply to] Can't Post

Hi,

when you say 'too much time', what periods of time are you talking about?
I've tested a piece of code similar to yours that also implements a message lifo. With 50 different messages, each at a length of 500 characters and up to 10 messages in the lifo, I could do 14000 checks per second on my system (P2/266).
Considering the overhead of the Net::IRC module (which I don't have installed), I'd guess that grep isn't the bottleneck of your application.
FYI, I've also checked some other ways of implementing this using hash tables. These were insignificantly faster on short messages (about 10%), but reasonably slower on longer messages.
Hope this helps.

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"



amphetamine
stranger

Jul 20, 2001, 11:26 PM

Post #4 of 4 (993 views)
Re: exists() / grep too slow ? [In reply to] Can't Post

wrote now a similar program using Tie::IxHash, between i tested it only on a p 100, need to test it on a faster linuxbox :/



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives