Announcement

Collapse
No announcement yet.

Why is my function slower than Ztree a console application?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why is my function slower than Ztree a console application?

    I am working on a function that will count the total number of files on a disk. My old standby Ztree can log my C drive in under two minutes. My way using FindFirstFile and FindNextFile takes more like six minutes. All I am doing in the loop is INCR MY_COUNTER. Is this one of those things where some ASM would speed this up?

    If I could get this fast the next step would be to put all the files and their attributes in an array.

    Ideas?

    Code:
    FUNCTION SUB_SPEED_FILE_COUNTER(BYVAL FILE_DRIVE_PATH AS STRING, FILE_EXTENTION AS STRING) AS LONG
    
       LOCAL SEARCH_HANDLE      AS DWORD               ' Search handle
       LOCAL STRUCT_FIND_DATA   AS WIN32_FIND_DATA     ' FindFirstFile structure
       LOCAL CURRENT_PATH       AS ASCIIZ * %MAX_PATH  
       LOCAL cFileName          AS ASCIIZ * %MAX_PATH  
    
    
       CURRENT_PATH  = FILE_DRIVE_PATH & "*." + FILE_EXTENTION
       SEARCH_HANDLE = FindFirstFile(CURRENT_PATH, STRUCT_FIND_DATA)  'GET A SEARCH_HANDLE FOR FindNextFile API CALLS
    
       IF SEARCH_HANDLE <> %INVALID_HANDLE_VALUE THEN                 
           DO
            INCR MY_COUNTER
           LOOP WHILE FindNextFile(SEARCH_HANDLE, STRUCT_FIND_DATA)
    
    END FUNCTION

  • #2
    Some people recommend using
    FindFirstFileEx
    and
    FindExInfoBasic
    so NTFS doesn’t look up the short filename.

    Another suggestion is to switch to a larger buffer using
    FIND_FIRST_EX_LARGE_FETCH

    I haven’t tried either.
    Politically incorrect signatures about immigration patriots are forbidden. Googling “immigration patriots” is forbidden. Thinking about Googling ... well, don’t even think about it.

    Comment


    • #3
      Thanks Mark, I will give those ideas a try!

      Comment


      • #4
        David, a side thing.

        Do you think being a console app makes it slower? (since PBWin and PBCC are the same except for user interface, the same "work" code would run at the same speed)

        ((also maybe Ztree only counts while FindFirstFile and FindNextFile get all that info for WIN32_FIND_DATA when only a count is needed.))

        Cheers
        .
        Dale

        Comment


        • #5
          David,
          What is the approximate file count?

          My similar code takes 5 minutes to count 500K files.

          Comment


          • #6
            Clarke, give this a try...you only want a count, correct?

            Comment


            • #7
              On the "count only" front, I revised my code to NOT keep files names and the count-only result was well under a minute for my mechanical D: drive. But I need to reboot to get rid of cache effects from multiple attempts. I'll reboot and try again.

              (revised)

              Comment


              • #8
                Ok, after a reboot, on a mechanical drive D:, my code got a count of 500K files in 4 min, so nothing any better than what you already have..

                Comment


                • #9
                  What type of variable is my_counter? What is its scope.

                  If you make it a local DWORD and use REGISTER my_counter and REGISTER search_handle in the function, you may find it is faster

                  Comment


                  • #10
                    Dave,

                    Something worth trying just to calibrate what you are doing. Try a command line from the root directory,
                    Code:
                    dir /s *.* > file.txt
                    See how long it takes.
                    hutch at movsd dot com
                    The MASM Forum

                    www.masm32.com

                    Comment


                    • #11
                      All good points! I will give them a try.

                      Comment

                      Working...
                      X