-
C++ CPU clock
Hi. I made a CPU clock that I think tests the speed of your CPU simply. here's the code. I was hoping that someone would run it, and give me feed back on the speed. I only have one computer. How do you change the CPU speeed!!
#include <iostream>
using namespace std;
int main()
{
int x;
x = 0;
int c;
c = 0;
cout << "start" << endl;
for (int Y = 0; Y <= 9; Y++)
{
c++;
cout << "second " << c << endl;
while (x <= 1400000000) //gigahertz speed here.. mine is 1.4 gHz.
x++;
x = 0;
}
cout << "end";
c = 0;
cin.get();
cin.get();
}
-
Also!
if you run the TASK MANAGER at the same time. you use 100% CPU time! No joke.
-
Tight loops like this can never be reliable sources of time measurement because your can't predict what the system load will be when you run them -- other tasks running at the same time might consume CPU time as well.
To access the CPU's clock you need to use low level system calls or assembly code.
Danny Kalev
-
Horrible code !
On Windows, simply use well-known native system apis to get CPU Speed (see Win32 grp for C code)
-
Its not just the tight loop and all that, the code assumes you can increment an integer in one clock cycle (you can, but you also jumped, incremented the loop counter, and did several other operations, probably 10-20 instructions in all depending on your settings).
It ignores the current load (as was mentiond) and also ignores pipelines, multi core cpu, non-fixed CISC instruction timing, debug/release/etc effects of compiler settings, and more.
If you want the CPU speed , ask it, the CPU knows what type it is and how fast it is, so does your operating system. If you want to test it against the known speed, you need to really sit down and study the problem, this is not the way to do it, its not a simple problem.
Similar Threads
-
Replies: 3
Last Post: 04-03-2008, 01:04 PM
-
By velkropie in forum Java
Replies: 5
Last Post: 03-24-2007, 11:09 AM
-
Replies: 3
Last Post: 04-14-2006, 03:44 AM
-
By Al Rest in forum vb.announcements
Replies: 0
Last Post: 06-10-2002, 03:19 AM
-
By zainorin in forum Java
Replies: 0
Last Post: 08-01-2000, 09:31 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks