473,793 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

100% CPU

The simple VB.NET loop:

for i = 1 to 30000000
' do something
next

drives the CPU on my computer to 100% utilization for the
duration of the loop. (Several minutes)

How can I modify this loop to let other (unrelated)
applications running on the same box get some CPU time?
TIA,

Bill

Nov 20 '05
14 4150
Cor,

Here are my results so far:
1. The statement

If i Mod 2 = 5000 Then
System.Threadin g.Thread.Sleep( 0)
End if

has almost no impact on CPU utilization (as viewed through
Win 2K Task Manager). The same seems to be true for setting

2.
Threading.Threa d.CurrentThread .Priority =
Threading.Threa dPriority.Lowes t

I find in both cases that the app still hogs around 97%
of the CPU but suprisingly the loop completion time
increases only slightly in either case (a fraction of a
second for 300,000 iterations)

Bill
-----Original Message-----
Hi Bill,

I never tried it, but did you tried the
threading.thre ad.priority = threadpriority. lowest

Will you give us a sign if it did help than we know it also?
Cor

for i = 1 to 30000000
' do something
next

drives the CPU on my computer to 100% utilization for the duration of the loop. (Several minutes)

How can I modify this loop to let other (unrelated)
applications running on the same box get some CPU time?
.



-----Original Message-----
Hi Bill,

I never tried it, but did you tried the
threading.thre ad.priority = threadpriority. lowest

Will you give us a sign if it did help than we know it also?
Cor

for i = 1 to 30000000
' do something
next

drives the CPU on my computer to 100% utilization for the duration of the loop. (Several minutes)

How can I modify this loop to let other (unrelated)
applications running on the same box get some CPU time?

.

Nov 20 '05 #11
On Mon, 29 Dec 2003 13:32:00 -0700, "Dick Grier"
<di************ **@msn.com> wrote:

(SNIP)
Application.Do Events DOES NOT issue a call to Sleep. (SNIP)Dick


Sorry- Apparently my bad.

My statement is TRUE for VB 4.0/5.0/6.0, though. That is, if you
believe the MSDN documentation (see "HOWTO: Determine the Differences
Between DoEvents and Sleep", Q158175.)

The .NET documentation does not say anything about it either way (that
I can find.)

// CHRIS

Nov 20 '05 #12
On Mon, 29 Dec 2003 16:46:40 -0800, "bill salkin"
<an*******@disc ussions.microso ft.com> wrote:
I find in both cases that the app still hogs around 97%
of the CPU but suprisingly the loop completion time
increases only slightly in either case (a fraction of a
second for 300,000 iterations)

Bill


Yes, I thought you were trying to avoid the "lock up" problem, where
other windows stop responding (or do so VERY slowly.)

If you want to decrease your CPU utilization, you'll have to put in
positive sleep values (try different values for the MOD value and the
Sleep(n) value).

The more you sleep, the less the CPU usage, and the longer it will
take for the loop to complete.

For k = 1 To 30000000
If k Mod 5000 = 0 Then
System.Threadin g.Thread.Sleep( 1)
End If
Next k

The value of 5000 is arbitrary. The more "work" you're doing in your
loop, the lower the value you'll want to use. Otherwise, it will make
little or no difference at all.

Play around with the numbers and get a feel for what combinations do.
Doing a Sleep(1) means (ideally) a 1 millisecond sleep. So that means
you can only do that 1000 times a second.

Since the k Mod 5000 allows it to go every 5000 itterations, your loop
will have an overhead the following overhead:

30 million itterations
times
1 millisecond sleep / 5,000 itterations

= 6,000 milliseconds sleep

= 6 seconds

You have to ask yourself how long you're willing to let the loop take
-vs- how much CPU usage you want to let it use.

// CHRIS

Nov 20 '05 #13
Cor
Hi Bill,

That the application uses the CPU normaly at about 97% is in my opinion
normal, I have that with every application.

However now you are testing, why do you not write two test programs, one
with the thread.sleep and one with the thread.priority lowest.

Start them at the same time and see the result.

I am curious for your answer.

Cor

1. The statement

If i Mod 2 = 5000 Then
System.Threadin g.Thread.Sleep( 0)
End if

has almost no impact on CPU utilization (as viewed through
Win 2K Task Manager). The same seems to be true for setting

2.
Threading.Threa d.CurrentThread .Priority =
Threading.Threa dPriority.Lowes t

I find in both cases that the app still hogs around 97%
of the CPU but suprisingly the loop completion time
increases only slightly in either case (a fraction of a
second for 300,000 iterations)

Bill

Nov 20 '05 #14
One problem, the load will be different depending on CPU type/speed.

How do you work arround that?
Maybe check spu load?

Schneider

"bill salkin" <an*******@disc ussions.microso ft.com> wrote in message
news:03******** *************** *****@phx.gbl.. .
Cor,

Here are my results so far:
1. The statement

If i Mod 2 = 5000 Then
System.Threadin g.Thread.Sleep( 0)
End if

has almost no impact on CPU utilization (as viewed through
Win 2K Task Manager). The same seems to be true for setting

2.
Threading.Threa d.CurrentThread .Priority =
Threading.Threa dPriority.Lowes t

I find in both cases that the app still hogs around 97%
of the CPU but suprisingly the loop completion time
increases only slightly in either case (a fraction of a
second for 300,000 iterations)

Bill
-----Original Message-----
Hi Bill,

I never tried it, but did you tried the
threading.thre ad.priority = threadpriority. lowest

Will you give us a sign if it did help than we know it

also?

Cor

for i = 1 to 30000000
' do something
next

drives the CPU on my computer to 100% utilization for the duration of the loop. (Several minutes)

How can I modify this loop to let other (unrelated)
applications running on the same box get some CPU time?

.



-----Original Message-----
Hi Bill,

I never tried it, but did you tried the
threading.thre ad.priority = threadpriority. lowest

Will you give us a sign if it did help than we know it

also?

Cor

for i = 1 to 30000000
' do something
next

drives the CPU on my computer to 100% utilization for the duration of the loop. (Several minutes)

How can I modify this loop to let other (unrelated)
applications running on the same box get some CPU time?

.

Nov 20 '05 #15

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

Similar topics

5
1576
by: | last post by:
newbie code -------------------------- #include <iostream> using namespace std; #include <cstring> class aaa {
6
6022
by: jslaybaugh | last post by:
I'm working on an ASP.NET 2.0 application and am having trouble with a very simple table layout. Using ASP.NET 2.0 it defaults to XHTML 1.0 Transitional and I am trying to comply. However, I cannot seem to get my table to render properly, so I pulled out all the server controls and just made a very simple HTML only page and am having the same problem still. The problem can bee seen in the code below. The top row is 100px high and the...
1
1884
by: Hypnotron | last post by:
Dim Dimensions as RectangleF = RectangleF.FromLTRB(-100, 100, 100, -100) debug.writeline( "Height = " & RectangleF.Height.ToString) Why the heck is height -200 ? How can you have a negative height? Width is ok, but height is clearly wrong. This looks very much like a bug to me. Further, when you try to check Dim mybool as Boolean = Dimensions.Contains(50.0,50.0)
18
2107
by: P.N. | last post by:
Hi! when i define array (any type) then compilator say that array is to large! ?? i need at least 10.000 instead 100. This is for numeric methods in "C" any sugestion? thx Greetings P
17
2143
by: Mike | last post by:
I'm trying to create a page: Three sections (left, topright and bottomright), each with a heading and scrolling (overflow) content. The size of these sections should be based upon the size of the user's viewable area in their browser. I'm close... really close, but I'm confused over how to mix specific measurements with percentages. When I began, things were quite nice: (http://play.psmonopoly.com/autosize.html). A little clunky in...
0
2163
by: Markus Olderdissen | last post by:
i want to create my page with 100% height. <table height="100%"works but is not correct by default. i saw various information how to do it with stylesheet. i really have problems to create my page. i want to have header on top and footer on bottom. content should be on top of the middle part. i always got scrollbars, even if my page isn't too large. perhaps, someone can show me to do it right. the following code describes my wish. ...
6
5811
by: =?Utf-8?B?VGhvbWFzWg==?= | last post by:
Hi, Is it possible to read a file in reverse and only get the last 100 bytes in the file without reading the whole file from the begining? I have to get info from files that are in the last 100 bytes of the file and some of these files are 600Mb -1 GB in size. I am getting "outofMemory.." exceptions on the largest files and the other files take "forever" to get the last 100 bytes. This is the code I have currently that works with...
1
10843
by: psion | last post by:
Hi, We have a gridview on a webpage, which we would like to be 100% of the table cell in which it is placed. When we specify the width to be 100%, this has no effect, but only if we specify a pixel number, i.e. 800, will the gridview be 800 px wide. Here is an example: http://www.valuetronics.com/Results.aspx?keywords=8050&x=0&y=0 And this may be related, but this page
8
1718
by: Mark Main | last post by:
I just bought Visual Studio 2008, I'm new to C# and trying to learn it. I'm stuck and would appreciate some help. I need to make the fastest code I can to work with a large key (it's 200 bytes wide) and add only the unique keys to a List<T>, Dictionary, Array... whatever is fastest because I'll be doing trillions of compares. The key is: ushort myBigKey = new ushort; I want to treat the entire array (all 100 instances) as one long...
1
2468
by: Meganutter | last post by:
Hello, i am having some troubles with DIVs. heres my setup i have a wrapper, 900px wide 100% height nested header 100% wide 20px high nested menubar 100%wide 80px high
0
9518
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10433
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6777
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.