FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Carlos Mora y la mala leche de la string concatenation
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Carlos Mora y la mala leche de la string concatenation
Posted: Fri May 04, 2018 05:21 PM
Mr. Rao,

Muchas gracias por sus tests.
Pues creo que tiene vd. razón.
Yo mismo he hecho mis test sencillos y arrojan tiempos sorprendentemente bajos para ~ 125 mb

Este es mi codigo:


Thank you very much for your tests.
I think you are right
I myself have done my simple tests and throw surprisingly low times for ~ 125 MB

This is my code:
Code (fw): Select all Collapse
function Data2Csv()
Local nI
Local cLin:= ""
Local cFull:= "\Tmp\articulos"
Local cIni
Local nRecords:= 0
Local nFCount
msginfo("Empezando")

cIni:= Time()

nH:= FCreate(cFull+ ".csv")

select 0
use (cFull)
nFCount:= FCount()
go top
do while !Eof()
   FOR nI:= 1 TO nFCount
      cLin+= Transform(FieldGet(nI), "")+ ";"
      IF nI != nFCount
         cLin+= ";"
      ENDIF
   NEXT
   FWrite(nH, cLin)
   nRecords++
   cLin:= ""
   SKIP
enddo
FWrite(nH, cLin)
FClose(nH)
CLOSE
mMsgInfo("Time End "+ Time()+ CRLF+ "Time Init "+ cIni+ CRLF+;
         "Records "+ Transform(nRecords, "")+ CRLF+;
         "Fields "+ Transform(nFCount, "") )
RETURN NIL



Manuel,

Voy a buscar en mi codigo que cosas estan consumiendo el tiempo.
La rutina de sutff para una cadena estará bien, pero creo que para mi es más importante encontrar donde se ralentiza el proceso realmente.


Gracias a todos por vuestro interés.
Volveré a decir más cuando tenga mas información.

Saludos.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Carlos Mora y la mala leche de la string concatenation
Posted: Sat May 05, 2018 01:44 AM

In my view, using (x)Harbour's COPY TO command is the fastest way to produce a CSV file. This command internally uses DBF2TEXT() function written entirely in C and is fairly optimized for the intended purpose.
There is no point in re-inventing the wheel. Even if we want to write a more efficient function, we can not do it with a Harbour level function or mix of Harbour and C level functions. We too need to write the entire function in C and in that case, are very likely to end up with a function similar to DBF2TEXT(). Obviously, the effort is not worth the result.

Regards



G. N. Rao.

Hyderabad, India
Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: Carlos Mora y la mala leche de la string concatenation
Posted: Sat May 05, 2018 04:31 PM

Bueno parece que Mr. Rao ha dado con la mejor solución para Paquito.
Pero esa no es la solución para algo genérico (no solo DBF) como quiere Carlos. ¿No? :twisted:

Lo hago o no? :roll:

______________________________________________________________________________

Sevilla - Andalucía
Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: Carlos Mora y la mala leche de la string concatenation
Posted: Sat May 05, 2018 05:14 PM

Paquito lo ralentiza la maquina virtual y el recolector de basura.

Mi propuesta sería hacerlo en C con lo que se evitaría dependencias como las que indica Carlos y te garantizo que la memoria no se fragmentaría nada.
Y ademas se podría usar para crear un bufer de escritura a un fichero cuya entrada podría ser cualquier cosa y no solo una DBF.

Yo lo hago si hace falta, si no, no...

Como dijo alguien: "Si hay que ir se va, pero ir pa ná..."

______________________________________________________________________________

Sevilla - Andalucía
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Carlos Mora y la mala leche de la string concatenation
Posted: Sat May 05, 2018 05:52 PM
As I said already in my posting above, my advice was limited to exporting contents of dbf to csv. (x)Harbour's code is quite optimized, keeping in view its capabilities like handling numeric, date, logical fields also, trimming, escaping of strings and also codepage issues.

I did appreciate your discussions on optimizing string operations, reducing memory fragmentation, etc. I clearly stated that I was not discussing that topic. Experts like Mr Carlos and Mr Xmanuel may continue with the topic.


My proposal would be to do it in C, which would avoid dependencies such as those indicated by Carlos and I guarantee that the memory would not fragment at all.
And it could also be used to create a write buffer to a file whose entry could be anything and not just a DBF.

Very good idea. Such a generic function would be useful for many purposes.
Regards



G. N. Rao.

Hyderabad, India
Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: Carlos Mora y la mala leche de la string concatenation
Posted: Sun May 06, 2018 07:40 AM

Ok, Mr. Rao.
La pongo en otro hilo, para que sea el inicio de una clase que todo el mundo pueda mejorarla.

El hilo se llamará: "TFBuffer, una clase para acelerar la escritura en ficheros"

______________________________________________________________________________

Sevilla - Andalucía

Continue the discussion