|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Mac speed
So I made a program that counts the number of loops a cpu can do in a millisecond. I ran it on my other notebook (a Dell 1.83ghz centrino duo), and got speeds much faster than what I got on my 2.0ghz Core 2 duo Macbook. Now, I can see the Mac is much faster, and the numbers say it should be...but from this, it "isn't".
My question is, do Macs put a limit on the number of loops that can be done? Does it limit the speed for battery life (or some other reason)? If you want to see the program, here it is. It's very simple. I included the source code, the readme, and a unix executable. You can run this program on windows, but you have to compile it yourself. It's in C++. (URL address blocked: See forum rules)=23378cf61a4bcc23639471613158446f I recommend a test less than 10 seconds. It's not good to run really long tests, as it heats up the cpu a bit, can drain batteries, etc. I've gotten pretty good results from a 1 second test (after all, there's 1000 milliseconds in a second!) |
|
#2
|
||||
|
||||
|
Mac OS X is very aggressive with throttling your CPU, for example my MBP shows that when idle the CPU will run at about 1.63Ghz, then when you start something that takes 100% CPU it can easily take 5 seconds for the OS to decide that it should run at the full CPU speed (its a waste to run @ full clock speed if its going to take 2 seconds @ 100% CPU, you would be able to tell the difference), in my case that's 2.16Ghz, and you just said that you don't run the test for more then a few seconds, also as soon as the high load is gone it will drop the clock speed again, if you want to be accurate then use the CHUD tools included with the dev tools and disable one core, this also has the affect of disabling the CPU throttling and should give you more accurate results, touch it also will waste the battery
also don't worry about CPU heat, the MBP has no problems with it (i have fun folding@home in Linux on it with the lid closed for a week straight and gotten no ill affects, the only problems you will have with heat is trying to touch the case another thing is that when compared to Linux, OS X is slower then Linux, its kernel uses an architecture that's slightly slower but more secure (it just checks itself more then Linux), when doing some operations in tight loops this can show, but since its not a common thing to do in code or hardware is just not optimized for this type of stuff, and because not even the hardware is optimized for that type of load processors will vary widely in their speeds at simple useless operations in tight loops if you want a decent way to test speed then use real life applications, like apply effects to audio and video samples, do some data analysis, or do math that gets you somewhere (like find PI) also your link got blocked, i would like to test the code in OS X vs Linux (on the same machine) but your url got blocked, maybe posting it again with some spaces or without the http may help
__________________
Feed ME |
|
#3
|
|||
|
|||
|
Code:
/*
CPU Speed Test V 8
Compatability version-No Monitoring
Monitoring is not so usefull, I've found it uses up too many resources on older systems to be usefull for
computing.
Programmed by: Greg Golinsky
*/
#include <iostream>
#include <fstream>
#include <ctime>
using namespace std;
int menu();
int main (int argc, char * const argv[])
{
int choice;
char yn;
char notes[100];
register long speed;
int delay;
choice = menu();
while(choice>0)
{
if(choice==1)
{
cout << "\nEnter number of whole seconds for test\n";
cin >> delay;
if(!cin)
{
exit(0);
}
cout << "\nTesting, please wait\n";
clock_t test = delay* CLOCKS_PER_SEC;
clock_t start=clock();
while(clock()-start<test)
{
speed++;
}
speed/=delay*1000;
cout << "Loops per millisecond: " << speed;
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
ofstream myFile;
myFile.open("radar_gun.txt",ios::app);
myFile << "\nLast test results on " << asctime (timeinfo) << " Test Length: " << delay << "\n Loops/ms: " << speed << "\n";
cout << "\nAdd notes? y/n \n";
cin >> yn;
if(!cin)
{
myFile.close();
exit(0);
}
else
{
if(yn=='y')
{
cout << "\nEnter notes\n ";
cin.get();
cin.clear();
cin.get(notes,100);
myFile << "\n ~ Notes: " << notes << "\n";
}
}
myFile.close();
cin.get();
cin.clear();
}
if(choice==2)
{
ifstream file("radar_gun.txt");
cout << file.rdbuf();
cin.get();
cin.get();
}
choice = menu();
}
return 0;
}
int menu()
{
int choice_menu;
cout << "\n"
<< "~~~~~~~~~~~~~~~~~~~~\n"
<< "Welcome to Radar Gun V.2.0!\n"
<< " 0) Quit\n"
<< " 1) Test\n"
<< " 2) Read Previous results\n"
<< "~~~~~~~~~~~~~~~~~~~~\n";
cin >> choice_menu;
return choice_menu;
}
That's the afore mentioned program. Without the .exe or the readme I included in the linked file. |
|
#4
|
||||
|
||||
|
i just did the test on my computer and i found your problem, your counter is rolling over, its not big enough, i ran the test and got 530 on my mac and 3,000,000+ of my Linux box, the mac is twice as fast, but i also i got many negative numbers depending on the level of optimization i used, i added some stuff to check for negatives and found that it rolls over in a tiny fraction of a second for both computers, in fact changing `speed` to an long long still resulted in negative numbers, even without compiler optimization
if you want to test like this then do use a fixed time, you need to time a loop of fixed size, and then you may easily run into compiler problems if it tries to optimize the loop away (if its only constants involved it will do that), but like i said before, its a bad testing method anyways, what your tring to is is measure the bogomips of a CPU, and its not actually related to CPU speed (only accurate with CPUs with the same core) |
|
#5
|
|||
|
|||
|
Hmm
I'll have to look into one of the better testing methods then. Thanks. |
|
#6
|
|||
|
|||
|
Well, I plan on making a cpu speed test using carbon, which will test instructions per time unit, maybe a PI calculation, and I'll throw these loops in as well.
I shortened the loop length, made the variable unsigned long long. I can't test it well, as I'm currently recording a show on my Mac, and that takes up some cpu ![]() Here's the current version: Code:
/*
CPU Speed Test V 8.1.0
Compatability version-No Monitoring
Shortened test length.
*/
#include <iostream>
#include <fstream>
#include <ctime>
using namespace std;
int menu();
int main (int argc, char * const argv[])
{
int choice;
char yn;
char notes[100];
unsigned long long speed;
float delay;
choice = menu();
while(choice>0)
{
if(choice==1)
{
delay = .01;
clock_t test = delay* CLOCKS_PER_SEC;
clock_t start=clock();
while(clock()-start<test)
{
speed++;
}
speed*=delay;
cout << "Loops per millisecond: " << speed;
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
ofstream myFile;
myFile.open("radar_gun.txt",ios::app);
myFile << "\nLast test results on " << asctime (timeinfo) << " Test Length: " << delay << "\n Loops/ms: " << speed << "\n";
cout << "\nAdd notes? y/n \n";
cin >> yn;
if(!cin)
{
myFile.close();
exit(0);
}
else
{
if(yn=='y')
{
cout << "\nEnter notes\n ";
cin.get();
cin.clear();
cin.get(notes,100);
myFile << "\n ~ Notes: " << notes << "\n";
}
}
myFile.close();
cin.get();
cin.clear();
}
if(choice==2)
{
ifstream file("radar_gun.txt");
cout << file.rdbuf();
cin.get();
cin.get();
}
choice = menu();
}
return 0;
}
int menu()
{
int choice_menu;
cout << "\n"
<< "~~~~~~~~~~~~~~~~~~~~\n"
<< "Welcome to Radar Gun V.2.0!\n"
<< " 0) Quit\n"
<< " 1) Test\n"
<< " 2) Read Previous results\n"
<< "~~~~~~~~~~~~~~~~~~~~\n";
cin >> choice_menu;
return choice_menu;
}
|
|
#7
|
|||||
|
|||||
|
I just caught this thread by chance, but it's interested me.
We're going to need a fast language that will support arbitrary length numbers. Let's try and calculate the factorial of 1,000,000 in scheme. scheme Code:
Run that from bash as follows (assuming gambit as your scheme interpreter): Source for gambit is here and the docs say it should compile on osx. Gambit is a very fast interpreter, i feel you will be surprised by the result.
__________________
~James [Not currently seeking freelance work] Like philosophy or interested in spirituality? Philosophorum. Game Dev Experts Forums Foresight Linux - Because your desktop should be cool! Linux FAQ FedoraFAQ UbuntuGuide |
|
#8
|
||||
|
||||
|
if your going to do it with just big numbers, how about this
in a text file Code:
scale=10000 sqrt(2) quit then in the terminal Code:
time bc maths.txt with maths.txt being the file above, that will calculate the sqrt of 2 to 10,000 digits, bc is a pretty much standard app on all UNIX computers and is preinstalled in OSX, here is what i get my 3.334GHz P4, Linux Code:
real 0m6.284s user 0m6.224s sys 0m0.004s my 2.16 GHz MBP Core Duo Code:
real 0m3.996s user 0m3.948s sys 0m0.016s keep in mind that that program is single threaded and doesn't benefit fro the extra core on my Mac |
|
#9
|
|||
|
|||
|
Quote:
What exactly do those results mean? |
|
#10
|
||||
|
||||
|
i'm not exactly sure what each thing from the time command means, but my understanding is that the real is how long it too to execute the program, user is how long the program spent executing its code, and sys is how long it spend inside system calls
as for how it works, well the text file is a script file for bc, it tells it to find the square root of 2 to 10,000 places, then exit, to run it you just run `bc maths.txt` (bc is a calculator for arbitrary precision math), `time` is a command that takes a single command as an argument, it will then execute that command and when it exits it will report how long it took, so if your computer if faster it should execute in less time, so lower numbers are better, also be aware that like most simple benches its still not that accurate, this will do some math and string manipulation to do the math, but its not necessarily representative of every task that your perform, if your benching for speed at a specific task then use that task and measure it as for my particular results, it shows that my 2.16GHz Core Duo MBP can do the square root of 2 in bc in about 4 seconds, my 3.334GHz P4 takes 6.2 seconds to do the exact same task, making my Mac about (6.4/4) or 1.6 times faster then my P4 at that same task, of course other tests will result in different results, for example i benched compiling the Linux kernel on both computers before, and the MBP was twice as fast (down to the second, in a task that took about 5 minutes), in this test my MBP was also running Linux, and i didn't spend any time to tune either setup, just made sure they did the same thing |
|
#11
|
|||
|
|||
|
How would I go about putting this into a C++ program?
Also, when I do what you mentioned, I get this: Code:
bc 1.06 Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. /maths.rtf 1: illegal character: \ /maths.rtf 1: illegal character: \ /maths.rtf 1: parse error /maths.rtf 1: illegal character: \ /maths.rtf 1: illegal character: \ /maths.rtf 1: illegal character: \ /maths.rtf 2: illegal character: \ /maths.rtf 2: illegal character: \ /maths.rtf 2: parse error /maths.rtf 2: illegal character: \ /maths.rtf 2: illegal character: \ /maths.rtf 3: illegal character: \ /maths.rtf 3: illegal character: \ /maths.rtf 3: illegal character: \ /maths.rtf 3: parse error /maths.rtf 3: illegal character: \ /maths.rtf 3: illegal character: \ /maths.rtf 3: illegal character: \ /maths.rtf 3: parse error /maths.rtf 3: illegal character: \ /maths.rtf 4: illegal character: \ /maths.rtf 4: illegal character: \ /maths.rtf 4: parse error /maths.rtf 4: illegal character: \ /maths.rtf 4: illegal character: \ /maths.rtf 4: illegal character: \ /maths.rtf 5: illegal character: \ /maths.rtf 6: illegal character: \ /maths.rtf 6: illegal character: \ /maths.rtf 6: parse error /maths.rtf 6: illegal character: \ /maths.rtf 6: illegal character: \ /maths.rtf 8: illegal character: \ /maths.rtf 8: illegal character: \ /maths.rtf 8: parse error /maths.rtf 8: illegal character: \ /maths.rtf 8: illegal character: \ /maths.rtf 8: illegal character: \ /maths.rtf 9: parse error /maths.rtf 10: parse error real 0m0.008s user 0m0.002s sys 0m0.006s ![]() |