473,574 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to decrease the cpu usage

Hello everyone.

i want to know how to decrease the cpu usage in my program.

i have to update quickly many data on gui,

so i tried to decrease the cpu usage on gui but i couldn't solve the problem.

i found the code with probloem why the cpu usage increased by debug..

Rectangle invalidateRect = new Rectangle(_deta ilVisibleRect.L eft,
_detailVisibleR ect.Top + item.Y - _vScrollBar.Val ue, _detailRect.Wid th,
item.Height);
this.Invalidate (invalidateRect );

if i don't call this code, then the cpu usage is ok,

but after i call this code, the cpu usage of my problem become between 10 ~
15%.

could you tell me how to solve this kind of problem if you have to update
many data
on GUI as fast as possible.

^^....help me
Mar 7 '08 #1
6 5700
lightdoll wrote:
Hello everyone.

i want to know how to decrease the cpu usage in my program.

i have to update quickly many data on gui,

so i tried to decrease the cpu usage on gui but i couldn't solve the
problem.

i found the code with probloem why the cpu usage increased by debug..

Rectangle invalidateRect = new Rectangle(_deta ilVisibleRect.L eft,
_detailVisibleR ect.Top + item.Y - _vScrollBar.Val ue,
_detailRect.Wid th, item.Height);
this.Invalidate (invalidateRect );

if i don't call this code, then the cpu usage is ok,

but after i call this code, the cpu usage of my problem become
between 10 ~ 15%.

Well, that's what causes the screen to redraw, so I would expect it to use
some CPU. Maybe it doesn't need as much as it currently uses though.
>
could you tell me how to solve this kind of problem if you have to
update many data
on GUI as fast as possible.
First thing that will help is to recognize that "as fast as possible" isn't
needed. Just "as fast as is perceptible to the user". So, for example, you
could limit animation to 30/second or data updates to 5/second and the user
won't notice the delay.

Next, although your code does a great job of defining the update region
correctly, if your paint code doesn't use the update region, there's no
benefit.

You might simply try this:

Add a timer with a period of 150ms.
Change the invalidate code to simply set a boolean dirty flag.
In the timer callback, if the dirty flag is set, invalidate the whole window
and clear the flag. (If you have multiple threads, you should use
Interlocked.Exc hange to clear the boolean flag and give you the old value)

This will probably decrease the number of repaints dramatically and
therefore save you a lot of CPU.
>
^^....help me

Mar 7 '08 #2
Jon
'First thing that will help is to recognize that "as fast as possible" isn't needed. Just "as fast
as is perceptible to the user".'

Ben: that can be pretty difficult to define, since you don't always know how powerful the end user's
computer is.
"Ben Voigt [C++ MVP]" <rb*@nospam.nos pamwrote in message
news:OF******** ******@TK2MSFTN GP05.phx.gbl...
lightdoll wrote:
Hello everyone.

i want to know how to decrease the cpu usage in my program.

i have to update quickly many data on gui,

so i tried to decrease the cpu usage on gui but i couldn't solve the
problem.

i found the code with probloem why the cpu usage increased by debug..

Rectangle invalidateRect = new Rectangle(_deta ilVisibleRect.L eft,
_detailVisibleR ect.Top + item.Y - _vScrollBar.Val ue,
_detailRect.Wid th, item.Height);
this.Invalidate (invalidateRect );

if i don't call this code, then the cpu usage is ok,

but after i call this code, the cpu usage of my problem become
between 10 ~ 15%.

Well, that's what causes the screen to redraw, so I would expect it to use
some CPU. Maybe it doesn't need as much as it currently uses though.
>
could you tell me how to solve this kind of problem if you have to
update many data
on GUI as fast as possible.
First thing that will help is to recognize that "as fast as possible" isn't
needed. Just "as fast as is perceptible to the user". So, for example, you
could limit animation to 30/second or data updates to 5/second and the user
won't notice the delay.

Next, although your code does a great job of defining the update region
correctly, if your paint code doesn't use the update region, there's no
benefit.

You might simply try this:

Add a timer with a period of 150ms.
Change the invalidate code to simply set a boolean dirty flag.
In the timer callback, if the dirty flag is set, invalidate the whole window
and clear the flag. (If you have multiple threads, you should use
Interlocked.Exc hange to clear the boolean flag and give you the old value)

This will probably decrease the number of repaints dramatically and
therefore save you a lot of CPU.
>
^^....help me


Mar 10 '08 #3
Jon
"Your requirements should include a minimum spec at which the client responds reasonably."

Even then it can be difficult to predict how fast that system is. Processor speed and memory size
and the other commonly mentioned parameters don't always give the full picture - two apparently
identical PCs can perform differently. You may not even have such a PC to test on.

I agree with your comment about 0.00001%, but I get the feeling that some programmers might just
check to ensure that it's fast enough on their development PC, and not consider that very worthwhile
speed improvements on slower PCs can still be made by making code changes.

I tend to mentally convert phases like "as fast as possible" into "as fast as is reasonably
possible".
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
Your requirements should include a minimum spec at which the client
responds reasonably.

It's certainly easier to define that than it is to optimise *forever*.
(There's always going to be something you can do to squeeze an extra
0.0001% of performance out of a system - but it's not a useful thing to
do.)
Mar 10 '08 #4
On Mar 10, 11:24 am, "Jon" <.wrote:
"Your requirements should include a minimum spec at which the client responds reasonably."

Even then it can be difficult to predict how fast that system is. Processor speed and memory size
and the other commonly mentioned parameters don't always give the full picture - two apparently
identical PCs can perform differently. You may not even have such a PC to test on.
While it's true that there are lots of factors to consider, it seems
fairly pointless making performance improvements if you've got no idea
when you're "done". I would say it's important practice to have a test
machine somewhere which is used as a lowest common denominator. It
won't cover *all* bases, but it's a good starting point.
I agree with your comment about 0.00001%, but I get the feeling that some programmers might just
check to ensure that it's fast enough on their development PC, and not consider that very
worthwhile speed improvements on slower PCs can still be made by making code changes.
On the other hand, other programmers tend to waste time on micro-
optimisations which will have no useful effect, and make code harder
to maintain.
I tend to mentally convert phases like "as fast as possible" into "as fast as is reasonably
possible".
But the definition of "reasonably " depends on who you ask, and without
both measurement and a goal, you're likely to waste time optimising
code that isn't really a problem to anyone.

Jon
Mar 10 '08 #5
Jon
Jon: I agree with much of what you say. "Reasonable " to me is a balancing act.

Jon
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:0a******** *************** ***********@u69 g2000hse.google groups.com...
On Mar 10, 11:24 am, "Jon" <.wrote:
"Your requirements should include a minimum spec at which the client responds reasonably."

Even then it can be difficult to predict how fast that system is. Processor speed and memory size
and the other commonly mentioned parameters don't always give the full picture - two apparently
identical PCs can perform differently. You may not even have such a PC to test on.
While it's true that there are lots of factors to consider, it seems
fairly pointless making performance improvements if you've got no idea
when you're "done". I would say it's important practice to have a test
machine somewhere which is used as a lowest common denominator. It
won't cover *all* bases, but it's a good starting point.
I agree with your comment about 0.00001%, but I get the feeling that some programmers might just
check to ensure that it's fast enough on their development PC, and not consider that very
worthwhile speed improvements on slower PCs can still be made by making code changes.
On the other hand, other programmers tend to waste time on micro-
optimisations which will have no useful effect, and make code harder
to maintain.
I tend to mentally convert phases like "as fast as possible" into "as fast as is reasonably
possible".
But the definition of "reasonably " depends on who you ask, and without
both measurement and a goal, you're likely to waste time optimising
code that isn't really a problem to anyone.

Jon
Mar 10 '08 #6
Jon wrote:
'First thing that will help is to recognize that "as fast as
possible" isn't needed. Just "as fast as is perceptible to the
user".'

Ben: that can be pretty difficult to define, since you don't always
know how powerful the end user's computer is.
The maximum perceptible refresh rate is not computer dependent.

The CPU usage needed to attain that frame rate is.
Mar 10 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1975
by: S.J. te Winkel | last post by:
Hi all, I have the following challenge: I want a table with 3 columns, in which -the left one has a maximum width of 470px -the middle one always has a fixed width of 180 px, -and the right one fills the remaining part of the screen. When you resize the window (smaller, or with a smaller resolution) I
2
5175
by: Sue | last post by:
I have a large database currently using up 30GB of space -- problem is, I am running out of space on my harddrive and so have to do some cleanup. One of the tables has a blob field and I find that I can safely delete some of this blob data because I will not be needing it in the database anymore. So the question is, if I delete some of the...
3
5127
by: | last post by:
I wrote an application and I want to decrease "system's" audio level .I dont want to do it via directshow must do it on directly window's wave volume control. Thankse
0
932
by: Christian Correa | last post by:
Has anyone experienced a performance decrease after migrating a project to ..NET? We migrated our code from ASP to ASP.NET, modifying sintax whenever needed. Basically, the application is the same but it now has its code separated into the .aspx and codebehind (.aspx.vb) files. After compiling the DLL in /bin and some debugging, the...
2
1615
by: Fish | last post by:
I have been researching the correct way to organize my solution so that it makes best use of VB.NET inherent ability to manage resources such as objects. My solution contains 2 projects and the main problem is that the mem usage continues to grow until the Service stops responding. I have received advice to: "create those objects at a...
12
5888
by: baibaichen | last post by:
i know that pImpl idiom can decrease compile time, but Is there any good practice/idiom to decrease link time? any reference or any idea is appreciated thanks
1
1342
by: Ravi Ambros Wallau | last post by:
Hi, it's me again: I have made an extensive search at google and finding a lot of information, but nothing that matters for me. My problem is that I've about three hundreds DLL's on bin folder. If I move half of these DLL's to another folder (outside of the application), load time decreases in the same scale. But all these moved DLL's are...
3
2680
by: Jesper, Denmark | last post by:
Hi, I've written a somewhat large program over the years (70.000 lines of code). When compiling the program I get a 2MB exe file. When running this program I get an corresponding image in the task manager showing a 40 MB memory allocation . Yes, the program allocates memory dynamicaly, but no where near this amout of memory. Of cause I...
8
1868
by: NAdir | last post by:
Hi, thank you for your help. My VB.Net application contains a document that the user can refresh at any time. The refresh works fine and needs to loop through few datatables (hundreds of rows). This works fine until I delete some rows in two tables. Just after the delete if I do the refresh there is a huge memory allocated and the time...
0
7814
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7737
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8075
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7827
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5316
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3752
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2253
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1072
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.