#212619 - 2017-08-14 04:15 AM
ReadLine()
|
AndreLuiz
Getting the hang of it
Registered: 2015-10-07
Posts: 89
Loc: Brasil, João pessoa
|
[ptbr] Olá a todos, eu vim até aqui para compartilhar algo que me incomodou bastante. É o seguinte, eu rodei um while, para capturar os dados de um arquivo com 4,419 linhas, e nesse momento ele levou 4s e 159ms, e para o que preciso é uma enorme tristeza. Enfim ai eu resolvi, testar uma coisa nova, usar o wshpipe() para ver a velocidade. então ele levou uns 344ms, podem testar se quiser.
Conclusão se o arquivo for grande, melhor usar o wshpipe para isso.
[eng(TRANSLATE)] Hello everyone, I came here to share something that bothered me a lot. This is the following, I ran a while, to capture data from a file with 4,419 lines, and at that point it took 4s and 159ms, and what I need is a huge sadness. Anyway, I decided to test something new, use wshpipe() to see the speed. So it took about 344ms, you can test if you want.
Conclusion If the file is large, best use wshpipe for this.
Codes:
/* READLINE() */
$handle=freefilehandle()
$=Open($handle, $Dir)
$Dir = ''
while (@error = 0)
$Dir = $Dir + ReadLine($handle) + @crlf
loop
$=Close($handle)
$Dir = Split($Dir, @crlf)
$Dir = Wshpipe('%comspec% /c Type "$Dir"', 1)
[ptbr] Não sei se mais alguém já sabia disso, mas é sempre bom trazer essas informações. Acho que vou poder na área de sugestões, algo do tipo, adicionar um ReadAll($handle, @crlf). Onde o primeiro parâmetro seria o id, e o segundo parâmetro seria o delimitador para as linhas.
[eng(TRANSLATE)] I do not know if anyone else already knew this, but it's always good to bring this information. I think I'll be able to in the area of suggestions, something like, add a ReadAll($handle, @crlf). Where the first parameter would be the id, and the second parameter would be the delimiter for the rows.
|
Top
|
|
|
|
#212624 - 2017-08-14 09:47 AM
Re: ReadLine()
[Re: AndreLuiz]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
You can use the File System Object to make use of ReadAll functionality:
Dim $ForReading, $ForWriting, $ForAppending
$ForReading = 1
$ForWriting = 2
$ForAppending = 8
Dim $TriStateUseDefault, $TriStateTrue, $TriStateFalse
$TriStateUseDefault = -2 ;-2 Opens the file using the system default
$TriStateTrue = -1 ;-1 Opens the file as Unicode
$TriStateFalse = 0 ;0 Opens the file as ASCII
Dim $strFile, $objFSO, $objFile, $objFileContent
$strFile = "C:\Windows\system32\drivers\etc\hosts"
$objFSO = CreateObject("Scripting.FileSystemObject")
$objFile = $objFSO.OpenTextFile($File, $ForReading, $TriStateTrue)
$objFileContent = $objFile.ReadAll
$=MessageBox($objFileContent,"Info")
$objFile.Close
|
Top
|
|
|
|
#212628 - 2017-08-15 10:29 PM
Re: ReadLine()
[Re: ChristopheM]
|
AndreLuiz
Getting the hang of it
Registered: 2015-10-07
Posts: 89
Loc: Brasil, João pessoa
|
[ptbr] Opa obrigado, dessa eu não sabia, vlw mesmo!! Mas mesmo assim usando objeto, é ainda mais rápido.
[eng(translate)] Hi, thanks, I did not know that, vlw !! But even so using object, it's even faster.
file read in (Kix) 641 ms file read in (obj) 203 ms
dim $start, $start1
$start = @ticks
$dir = ReadFileToArray( $filename )
$start = @ticks - $start
$start1 = @ticks
$objFSO = CreateObject("Scripting.FileSystemObject")
$objFile = $objFSO.OpenTextFile($filename, 1, 0)
$filename= Split($objFile.ReadAll, @crlf)
$objFile.Close
$start1 = @ticks-$start1
[ptbr] O arquivo possuí 30.058 linhas, 464kb. Enfim muito obrigado aos dois, foi muito valioso isso.
[eng(translate)] The file has 30,058 lines, 464kb. Anyway, thank you very much, it was very valuable.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|