x
This website is using cookies. We use cookies to ensure that we give you the best experience on our website. More info. That's Fine
HPC:Factor Logo 
 
Latest Forum Activity

eVB grid control - how to speed it up.

Cyberstorm Page Icon Posted 2006-02-22 11:00 PM
#
Avatar image of Cyberstorm
Factor Fanatic

Posts:
51
Location:
South Dakota
Status:
Here are some insights as to how to speed up filling in a grid control. I timed the amortization chart program I made and found the following;

1. Using the controls "additem" method is horribly slow. I believe this was designed to allow you to insert rows into the table where needed, the method takes care of shifting the rest of the rows down etc.

Example (bad);

for iCount = 1 to 360 gridControl.AddItem ("Cat" & vbTab & "in" & vbTab & "the" & vbTab & "Hat" next iCount


Using this method in my amortization chart program took forever, just shy of 2 minutes!! 117 seconds to be precise. The better way to go is to pre-allocate your chart and fill as follows;

Example (better);
grdControl.Rows = 360 for iCount = 1 to 360 grdControl.TextMatrix(0, 0) = "Cat" grdControl.TextMatrix(0, 1) = "in" grdControl.TextMatrix(0, 2) = "the" grdControl.TextMatrix(0, 3) = "Hat" next iCount



This was like lightning compared to other method, total time was 12 seconds.

2. Set the control to visible=false while updating and then back to true when complete.

Example (best);
grdControl.Visible = False for iCount = 1 to 360 grdControl.TextMatrix(0, 0) = "Cat" grdControl.TextMatrix(0, 1) = "in" grdControl.TextMatrix(0, 2) = "the" grdControl.TextMatrix(0, 3) = "Hat" next iCount grdControl.Visible = True


Final result, the grid is filled in 5 seconds!! Of course for the "bestest" time - code it in C (or assembly )
Also, my code had proper indenting, however I can't figure out how to get that to "stick" in the posting. Hopefully still readable enough! If someone can tell me how to do that, I'll come back and edit this post to make it look purdy!

Hope that helps someone coding in VB. Also I attached the amortization chart for anyone interested - the 2 minute slow one - you can get the fast one when you register the software at my site for the hpc:factor special of $40, mwwwaahhhahhahaaa - er no, actually the fast one is attached! Ohh, almost forgot - no error checking and the starting date does nothing at this point so use at your own risk - AND if your HPC blows up - don't call me!!



Edited by Cyberstorm 2006-02-22 11:04 PM
 Top of the page
abyssknight
abyssknight Page Icon Posted 2006-02-22 11:02 PM
#
Status:
Awesome!

Anyone care to calculate the Big-Oh notation for that? Nah, didn't think so...

Speaking of assembly... I have some MIPS/Intel assembly knowledge. Wonder if it'd work...
 Top of the page
chiark Page Icon Posted 2006-02-23 3:00 AM
#
Avatar image of chiark
H/PC Sensei

Posts:
1,330
Location:
North of England
Status:
Big O is referring to the complexity of the algorithm - quite what the "Big Oh" is referring to is probably not best guessed at

And well done for sorting that out. Thinking back, I think the same issue exists on the full Win API too... I seem to remember coding around this sort of thing in 1997 for a large bank's front end system
 Top of the page
ShadowMaster Page Icon Posted 2006-02-23 7:13 AM
#
Avatar image of ShadowMaster
H/PC Philosopher

Posts:
297
Location:
Chile
Status:
interesting tips
 Top of the page
Jump to forum:
Seconds to generate: 0.140 - Cached queries : 59 - Executed queries : 11