473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

need code to peg CPU for 10 seconds

I need code to peg the CPU for 10 seconds to test some background
threads. Sleep obviously doesn't do that. How do I code a busy loop
that won't get removed by the compiler? Thanks.

Feb 5 '07 #1
4 3939


"not_a_commie" <no********@gmail.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
>I need code to peg the CPU for 10 seconds to test some background
threads. Sleep obviously doesn't do that. How do I code a busy loop
that won't get removed by the compiler? Thanks.
DateTime endTime = DateTime.Now.AddSeconds(10);
int i = 0;
while (DateTime.Now < endTime) { i++; }
You'd have to run 2 or 3 instances of this program at once to really peg the
CPU though...on my machine, something is preventing the app from using more
than 50% of the CPU per process...which, is pretty good since I don't want
any apps bogging down my system :)

HTH,
Mythran
Feb 5 '07 #2


"not_a_commie" <no********@gmail.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
>I need code to peg the CPU for 10 seconds to test some background
threads. Sleep obviously doesn't do that. How do I code a busy loop
that won't get removed by the compiler? Thanks.
Note on my prev thread, I have a hyperthreaded CPU which is why it is not
using more than 50% CPU on my machine...may end up using more for you
depending on your CPU..

HTH,

Mythran
Feb 5 '07 #3
not_a_commie wrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
>I need code to peg the CPU for 10 seconds to test some background
threads. Sleep obviously doesn't do that. How do I code a busy loop
that won't get removed by the compiler? Thanks.
"Fields that are declared volatile are not subject to
compiler optimizations that assume access by a single thread."
(http://msdn2.microsoft.com/en-us/library/x13ttww7.aspx)

Regards,
Christian
Feb 5 '07 #4
"Mythran" <ki********@hotmail.comwrote in message
news:AA**********************************@microsof t.com...
>

"not_a_commie" <no********@gmail.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
>>I need code to peg the CPU for 10 seconds to test some background
threads. Sleep obviously doesn't do that. How do I code a busy loop
that won't get removed by the compiler? Thanks.

DateTime endTime = DateTime.Now.AddSeconds(10);
int i = 0;
while (DateTime.Now < endTime) { i++; }
You'd have to run 2 or 3 instances of this program at once to really peg the CPU
though...on my machine, something is preventing the app from using more than 50% of the
CPU per process...which, is pretty good since I don't want any apps bogging down my system
:)
This means you are running on an HT CPU, which means that this is pretty bad because your
CPU cannot server any other thread, or otherwise stated your system is bogged down by this
single thread.

Willy.

Feb 5 '07 #5

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

Similar topics

1
by: roll | last post by:
Hi! I have to get the difference between date 1 and date 2 (that is date 2 minus date 1) ; the format is timestamp. How can I do it? Does anybody have an example of code? Thank you.. Pero
4
by: Peter Lin | last post by:
Dear all; I need to monitor a xml file so that I can update my data in hashtable, but the problem is it will trigger more than one event for a lastwrite action(I trigger this action by add...
10
by: WhiteSocksGuy | last post by:
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have...
5
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when...
1
by: Steve Jacobs | last post by:
Hi, I need to run a vb.net or aspx.net file every 10 seconds. The Task Scheduler in Windows 2003 Server can only do it every 1 minute at the minimum, but I need it every 10 seconds. Is it...
1
by: Ron Harter | last post by:
I have inherited a project that where I need to convert time form the DataTime format to the old form of seconds since 1/1/70. I can't locate any functionality in the framework (2.0) that even...
5
by: not_a_commie | last post by:
So I have a motherboard with multiple CPU sockets. It seems that if I create a StopWatch on one thread and then call the Elapsed member from a different thread that sometimes I get a tick count...
4
by: MrDeej | last post by:
Hello guys! I am trying to use trevors wait function on my odbc database for a countdown function. But this function is not stable as it sometimes dosent actually wait before launching next line...
2
by: nitric | last post by:
Hey guys, I am taking Programming I this semester and I am completely new to Java. for my FIRST assignment i need to write a Java program that will give me hours, minutes and seconds after I type...
4
by: ndedhia1 | last post by:
I am reading in a file to see what delays I am getting on what IP address: QuoteBlockTiming exceeded 1000 ms: 1684 --- Fri Nov 06 06:09:10 CST 2009 170.137.94.95 Class key = 649126730 block...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...

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.