Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Code Samples & Tips
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Code Samples & Tips Share your recent discoveries and ideas with other users.


Tip on how not to write speedy code


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-26-2008, 01:27 PM
Junior Member
 
Join Date: Sep 2007
Posts: 28
Exclamation Tip on how not to write speedy code

I wrote a little program the other day that scanned through a multi-megabyte file looking for certain bit sequences and then decoding them. I was surprised how slow it ran. After some testing I ran across some interesting observations.

Take this simple code below.

Code:
Sub App_Start
	form1.Show
	form1.Refresh
	For i = 1 To 100000
		label1.Text=i
'		label1.Refresh
		form1.Refresh
	Next
	label1.Text="done"
	form1.Refresh
End Sub
The code above takes about 5 minutes to run.
Change the form1.refresh to label1.refresh and it runs in 10 seconds!
Comment out label1.refresh and it runs in 6 seconds!!
Comment out label1.text and it runs in less than second!!!!

So the point here is that from now on I'll make sure my number crunching, loops, etc.. are done without refreshing the data on screen if I want speedy code. We are talking about 2 orders of magnitude in difference here!!

Going to go back and rewrite some of my code now.

This is was all done on the desktop. I haven't tried this on a PPC yet.
Reply With Quote
  #2 (permalink)  
Old 01-30-2008, 09:20 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,752
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

You might try the DoEvents statement rather than Refresh a specific control. DoEvents processes any message in the apps' message queue and so will update anything that needs updating rather just a specific control. Forcing a full Form Refresh will redraw the entire form, and as you have found out is not a good idea!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Write IF error GallyHC Questions & Help Needed 4 06-02-2008 06:42 PM
code to write out combinations e.g. (10 choose 3) Stellaferox Questions & Help Needed 4 02-04-2008 06:51 AM
Need a format to write large .dat file with numbers Stellaferox Questions & Help Needed 4 02-04-2008 02:16 AM
opti-compile gives speedy exe Put Claude Code Samples & Tips 1 01-09-2008 06:08 AM
Unbuffered Write / Buffer Flush davidmw Basic4ppc Wishlist 5 07-07-2007 11:26 PM


All times are GMT. The time now is 03:35 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0