News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Speed Difference?

Started by jckl, February 23, 2006, 03:56:52 AM

Previous topic - Next topic

jckl

Is there enough speed difference to notice in a loop between .while and using jumps.. For example if you had the fillowing would one be faster or better to use?


     .while (eax < Len)
       mov byte ptr [ebx+eax], '0'
       inc eax
     .endw




       @@:
       cmp eax, Len
       jge @F
       mov byte ptr [ebx+eax], '0'
       inc eax
       jmp @B
       @@:

hutch--

There is a simple solution to this question, just test both and see which one is faster. On a wider scale, if its truly speed critical code, you may be able to do it faster than either alternative here, it looks like a zero fill algo so it can probably be hurried up a lot.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jckl

what about in general.. would jumps perform faster than while loops or if statements?

hutch--

This is what the loop code disassembles to.


    jmp lbl1

  lbl0:
    mov BYTE PTR [eax+ebx], 30h
    inc eax

  lbl1:
    cmp eax, [ebp-4]
    jb lbl0


The manual code is no faster but there are tricks like unrolling or if its safe, doing DWORD writes on the buffer.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jckl

ok thx... one otherquestion i have is if insert 4000 items into a listview using a loop the listview seems to take a few seconds to display. Is there a way to speed that up so it dont take the extra time to display the results?

hutch--

One trick is to turn off the display update while you are loading the listview.

    invoke SendMessage,hWin,WM_SETREDRAW,FALSE,0

  ; load the list

    invoke SendMessage,hWin,WM_SETREDRAW,TRUE,0

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jckl

awww that did the trick i was looking for.. Thanks again  :toothy

donkey

Hi jckl,

Another way to speed up adding items to a listview is to tell it how many items you will be adding in advance, that way it is not constantly allocating memory for the new items, this is done using the LVM_SETITEMCOUNT message. I have found that for listviews with large amounts of data it can help alot. If you have extremely large numbers of items it is always best to use a Virtual ListView and that way it will appear instantly as your program is responsible for providing the data and the ListView does not need to store the data. Virtual ListViews are created using the LVS_OWNERDATA style. You can see an example of a Virtual ListView in the hex viewer of WinExplorer.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable