Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
load and assign 3MB, 70,000 lines txt to array in a minute?
#1
Hi everyone,

I have a question, Is it possible to load a text file as large as 3 MB, around 70 thousand lines and then assign each lines to array variable in less than a minute or in a matter of seconds? It took me about 5 minutes to load and assign everything to array variable. I thought maybe there's a way to load the file directly to memory then it might be faster to fill in the data to array variable?

this is the code that I used:

str data
data.getfile("$desktop$\data.txt")
data.trim
int nrlines=numlines(data)

ARRAY(str) lines.create(nrlines)

for i 0 nrlines
lines[i].getl(data i)
#2
Place minus before i, and the time will be 120 milliseconds. From getl help: "If n is omitted or negative, finds next line. It is much more effective, than to use growing n every time.". Because, when positive line number is specified, getl searches for n-th line from the beginning of the string, 70000 times in 3 MB. If line number is omitted or negative (any negative number), getl remembers previous line in that string, and searches from that place, not from the beginning.


lines[i].getl(data -i)
#3
Thanks a lot!! I wouldn't realize that before.


Forum Jump:


Users browsing this thread: 1 Guest(s)