From: | Bryan K. Williams |
Date: | 21 Jan 2000 at 04:14:27 |
Subject: | Re: variable names |
From: "Bryan K. Williams" <icar@evilgeniuses.org>
Hello Andrew,
Here's a much faster way of doing your letter count. As a comparison, I
ran (both on the same '060 A2000) my script on a 2,388,542 byte file
(phpmanual.rtf) that was on my harddrive, and yours on a much smaller file
(a .newsrc file of 44,877 bytes) that was on Ram_Disk. Gee, doesn't seem
to be a fair test ;^) Mine took 32 seconds compared to 43 seconds.
Really, though, I did something similar long ago and someone was nice
enough to show me this better way, though I can't remember who. The one
limitation is that it uses more memory, but you can adjust that downward
by changing the 65000 to a lower number. So here's a much faster script:
--------------------
/*
** Faster way to count individual letters
*/
options results
/*
** This sets letter.<anything> to 0.
** Faster than doing a loop for each item.
** Bad if you had a previous item set or need
** a Letter variable unset.
*/
letter. = 0
/*
** not exiting nicely if it doesn't open ;^)
*/
call open('x1','D:puzzel4.txt','R')
do until EOF('x1')
/*
** reading 1 char at a time is very slow
** Let's get as big a chunk as we can
*/
LongString = readch('x1',65000)
/*
** How big is the string really
*/
len = length(LongString)
/*
** increment for each letter, change it
** to whatever range you need.
*/
do x= 65 to 90
/*
** use the Compress() function to delete
** all the characters of the specific type
** and subtract from original length to
** calculate how many. Compress is very fast.
*/
letter.x = letter.x + (len - length(compress(LongString,d2c(x))))
end
end
call close('x1')
do i = 65 to 90
say d2c(i)||" "|| letter.i
end
exit
--------------------------
Later,
Bryan (with a Y ;^)
--------------------------- ONElist Sponsor ----------------------------
Independent contractors: Find your next project gig through JobSwarm!
You can even make money by referring friends.
<a href=" http://clickme.onelist.com/ad/jobswarm2 ">Click Here</a>
------------------------------------------------------------------------
ARexx mailing list - No flames, no overquoting, no crossposting. Unsubscribe: Blank mail to mailto:arexx-unsubscribe@onelist.com