I had a hunch that the SUBSTR approach becomes less and less efficient as
the string length increases in size so I put the following code together.
Note - I commented out the one million test as it takes about 5 minutes on
my machine.  The results are impressive! - Joe

? 'One million Character by character reads from strings of different
lengths'
DO Readc WITH 10
DO Readc WITH 100
DO Readc WITH 1000
DO Readc WITH 10000
DO Readc WITH 100000
*DO Readc WITH 1000000

? 'One million Character by character reads from a file'
DO Freadc WITH 1000000
RETURN

FUNCTION Readc
PARAMETERS m.StrLen
m.String = REPLICATE('t', m.StrLen)
m.cnt = 0
m.Start = SECONDS()

DO WHILE m.cnt < 1000000
  FOR m.x = 1 TO m.StrLen
    m.ch = SUBSTR(m.String, m.x, 1)
    m.cnt = m.cnt + 1
  ENDFOR
ENDDO
? m.StrLen, SECONDS() - m.start
return

FUNCTION Freadc
PARAMETERS m.StrLen
m.Start = SECONDS()
STRTOFILE(REPLICATE('t', m.StrLen), 'Ftest.tmp')
m.InFile = FOPEN('Ftest.tmp')
FOR m.x = 1 TO m.StrLen
  m.ch = FREAD(m.InFile, 1)
ENDFOR
FCLOSE(m.InFile)
ERASE Ftest.tmp
? m.StrLen, SECONDS() - m.start
return


On Sun, Sep 11, 2016 at 11:57 AM, Ted Roche <tedro...@gmail.com> wrote:

> The problem with that kind of approach is essentially, the algorithm
> counts words one at a time to get to the one you want: 1,2,3,... which
> is fine for 100 words, but unworkable for a million.
>
> On Sat, Sep 10, 2016 at 9:06 PM, Laurie Alvey <trukke...@gmail.com> wrote:
> > To split a string into words you can use something like this:
> >
> > n = GETWORDCOUNT(mysring)
> > FOR i = 1 TO n
> >      ? GETWORDNUM(mystring,i) && do something with the word
> > ENDFOR
> >
> > Laurie
> >
> > On 10 September 2016 at 16:02, Stephen Russell <srussell...@gmail.com>
> > wrote:
> >
> >> Is there a split function in VFP to take every word of the string into
> an
> >> array?  Then you could parse each array element till done.
> >> C# example here.
> >>
> >> string s = FromYourTextfile;
> >>         // Split string on spaces.
> >>         // ... This will separate all the words.
> >>         string[] words = s.*Split*(' ');
> >>         foreach (string word in words)
> >>         {
> >>             // parse your word here for what you need.
> >>         }
> >>
> >>
> >> On Sat, Sep 10, 2016 at 12:32 AM, Joe Yoder <j...@wheypower.com> wrote:
> >>
> >> > I have  a routine that processes each character in a file.  The file
> I am
> >> > working with is over 2 million characters long.  I pull it into a
> memory
> >> > variable with filetostr and then process each character with the
> substr
> >> > command.  Apparently substr has problems when dealing with a long
> string
> >> as
> >> > the process is painfully slow.
> >> >
> >> > I suspect that I will be better off using the low level file routines
> to
> >> > read one character at a time but thought maybe someone knows of a way
> to
> >> > speed up the approach I am using now.
> >> >
> >> > Thanks in advance,
> >> >
> >> > Joe
> >> >
> >> >
> >> > --- StripMime Report -- processed MIME parts ---
> >> > multipart/alternative
> >> >   text/plain (text body -- kept)
> >> >   text/html
> >> > ---
> >> >
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/cabqednvvcuubkg74m5fqcium3w0yn8ytji-5_yfgbgxgar5...@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to