Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorting big file
#1
I am trying sort a textfile (800 Kb).

Using qsort takes >5 min.

Do you know another way in QM?
#2
I tested with winapiqm.txt, which is 379 kb. It took 4 seconds. Then I replaced str to lpstr, and then it took 100 ms. The slow part is converting string to array at the beginning. It must allocate and copy near 100000 strings. With lpstr, string allocation/copying is eliminated.

Macro:
Code:
Copy      Help
int t1=GetTickCount

str a.getfile("$qm$\winapiqm.txt")

ARRAY(lpstr) b
tok a b -1 "[]" 1

qsort &b[0] b.len sizeof(lpstr) &sortlpstrproc

str a2=b ;;don't use a, because strings in b actually are stored in a

int td=GetTickCount-t1
out td
;
ShowText "" a2

Function sortlpstrproc:
Code:
Copy      Help
function[c] lpstr&s1 lpstr&s2
int i=q_stricmp(s1 s2)
if(i>0) ret 1
if(i<0) ret -1
#3
Thanks.


Forum Jump:


Users browsing this thread: 2 Guest(s)