Jump to content

Slowing When Loop Recycle


Recommended Posts

my script run more slowly each time the loop recycle i think it because he have to search for the right line. this script it for spliting a word file into multiple little one.

; World List Splitter
; Created 2005-janvier-13 By Greenseed
; version 0.1 
;MsgBox(4096,"",$_path)

;**************************************************************************************
;*****************************************Debut****************************************
;**************************************************************************************

;declare option
AutoItSetOption ( "trayiconDebug",1 )

;-------Declare Variable---------
$_var1 = 1
$_checkdupe = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
$_bytesread = 0
$_timerdif = 1000
$_line = 1

; Selection du fichier
$_wordfile = FileOpenDialog ( "Choisis Le Fichier De Mots A Spliter", "c:\", "All (*.*)" , 1 + 2)

; calcule le path
$_pos = StringInStr ( $_wordfile, "\" , 0, -1)
$_len = StringLen ( $_wordfile )
$_todelete = $_len - $_pos + 1

; path ou lire et ecrire le fichier
$_path = StringTrimRight ( $_wordfile, $_todelete )

; ouvre le fichier a lire
$_filetoread = FileOpen ( $_wordfile, 0 )
$_bytestoread = filegetsize ( $_wordfile )

;ProgressOn ( "title", "maintext" [, "subtext" [, x pos [, y pos [, opt]]]] )
ProgressOn ( "Progression", "", "", 0, 0, 2 + 16)
$_timer = TimerInit()

;ouvre le fichier a ecrire
$_wordsplit = $_path & "\wordsplit_" & $_var1 & ".txt"

$_filetowrite = Fileopen ( $_wordsplit, 1 )

;lit le fichier jusqu'a fin
    While 1
        $_readline = FileReadLine ( $_filetoread, $_line )
        while $_readline = $_checkdupe
            $_Checkdupe = "aaaaaaaaaaaaaaaaaaaaaaaaaa"
            $_line = $_line + 1
            $_readline = FileReadLine ( $_filetoread, $_line )
        wend
;check la grosseur du fichier a ecrite si ye plus grand que 10meg il en ouvre un autre
    while Filegetsize ( $_filetowrite ) > 10240000
        FileClose ( $_filetowrite )
        $_var1 = $_var1 + 1
        $_wordsplit = $_path & "\wordsplit_" & $_var1 & ".txt"
        Fileopen ( $_wordsplit, 1 )
    wend 

;Ecrite la ligne au fichier $_filetowrite
     $_checkdupe = $_readline 
     $_bytesread = $_bytesread + Stringlen ( $_readline  )
     FileWriteLine ( $_filetowrite, $_readline  )
     $_line = $_line + 1
    _progress()
        if @error = -1 then exitloop
    Wend 
    
;ferme les fichiers et quitte
    fileclose( $_filetoread )
    fileclose( $_filetowrite )
    exit 

func _progress()
if Timerdiff($_timer) > $_timerdif then
    $_timerdif = $_timerdif + 1000
    $_pourcent = Int($_bytesread * 100 / $_bytestoread)
    $_speed = round( $_bytesread * 1000 / timerdiff ( $_timer ) / 1024, 2); Kbytes/seconde
    $_eta = round ( round ( $_bytestoread - $_bytesread, 0 ) / 1024 / $_speed,2 ); seconde
    If $_speed > 1024 Then 
               $_speed = Round($_speed / 1024, 2) & " Mb/Sec"
           Else
               $_speed = $_speed & " Kb/Sec"
    EndIf
    If $_eta > 0 Then
        If $_eta > 60  Then
            $_eta = Round($_eta / 60, 0) & " Minutes"
            if $_eta > 60 then
                $_eta = round( $_eta / 60, 0) & " Heures"
            endif
        Else
            $_eta = $_eta & " Secondes"
        EndIf
    Else
        $_eta = ""
    EndIf
    ProgressSet($_pourcent, "Etat: " & $_eta & " @ " & $_speed)
endif
endfunc
    
    

;**************************************************************************************
;*******************************************End****************************************
;**************************************************************************************

GreenseedMCSE+I, CCNA, A+Canada, QuebecMake Love Around You.

Link to comment
Share on other sites

  • Developers

Why would the answer be different then the one you got with your previous question? Looks like you still do the same thing .....

A quick scan shows you are using the FilReadLine function with a line number parameter.  If you read line 10 the file is rewound and then 1,2,3....10 are read.  So for big files doing it like this gets slower and slower.

<{POST_SNAPBACK}>

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

my script run more slowly each time the loop recycle i think it because he have to search for the right line. this script it for spliting a word file into multiple little one.

Yes, it is as you suspect, and for the reason JdeB states. I tried your script with and without the line number option in the FileReadLine function, on a 5,000 line file of 563KB, and the elapsed time was 97 seconds with the line number, and only 1.62 seconds without the line number. The file it produced was identical for both methods. That being the case, just remove the line number option from both places.

Phillip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...