[SOLVED] why: the same program runs multiple times but get very different results
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
unless your processor is 100% dedicated to one process, which is impossible short of building a hardware device just to run that task, the execution time will be guaranteed to vary because the process has to share processor time with other processes, even a 'bare metal' execution of your task might have variances in execution time as no environment is perfectly consistent.
To be fair, if the CPU is cacheless, if the RAM is SRAM and if there is no DMA, i.e. if there are no factors beyond program control, the environment is consistent - the whole thing is just a deterministic synchronous circuit. But a very dedicated HW is needed for this.
unless your processor is 100% dedicated to one process, which is impossible short of building a hardware device just to run that task, the execution time will be guaranteed to vary because the process has to share processor time with other processes, even a 'bare metal' execution of your task might have variances in execution time as no environment is perfectly consistent.
Yes but that is for elapsed time.
jiml8 is talking about the actual time that the program is executing on the CPU.
Sergei Steshenko is talking about actual elapsed time.
I'm not sure what the original poster's program is measuring but I believe that it is actual elapsed time.
jiml8 has said that there is a distinction between CPU time and actual elapsed time/wall clock time.
Sergei Steshenko is ignoring this distinction and talking about actual elapsed time issues.
It's pretty funny so far.
Last edited by stress_junkie; 12-09-2010 at 04:50 PM.
jiml8 is talking about the actual time that the program is executing on the CPU.
Sergei Steshenko is talking about actual elapsed time.
I'm not sure what the original poster's program is measuring but I believe that it is actual elapsed time.
Time it takes to perform cache and/or RAM cycles is still CPU time. I.e. if you go to your BIOS and choose slower DRAM settings, every benchmark of yours will show larger CPU time. This is because CPU time is the sum of durations of CPU instructions executed during task executions. So slower cache (rather, cache misses) and slower RAM do increase this time.
... Sergei Steshenko is ignoring this distinction and talking about actual elapsed time issues.
It's pretty funny so far.
Nonsense. You are ignoring the fact that CPU knows nothing (at instructions level) about HW wait states and about the facts of it relinquishing the bus to higher priority masters.
Nonsense. The CPU has no notion of memory refresh. The CPU can't do anything externally while in wait cycles, for example, it can't push current task's registers on stack, it can't process an interrupt.
To the same extent the CPU has no knowledge about DMA.
...
*sigh*
You need to go study about non maskable interrupts. X86 family exerts an NMI for memory refresh. And for DMA. Also, the memory controller in an x86 system is located...where exactly? On the CPU chip. Where else. So of course the processor knows about memory refresh.
Quote:
Spend about $100 or something like that (well, more - you'll need an oscilloscope too), buy a cheap development board for a simple controller - preferably without pipeline, and do something on bare metalfrom scratch. I.e. write your own BIOS first.
For me it was quite revealing in the late eighties to develop an in-circuit emulator and to use it to debug HW and SW.
I was building SBCs starting in the mid '70s. And an oscilloscope is close to useless these days for that kind of thing. You need a network analyzer.
Been there. Done that. Got the T-shirt.
Edit:
Oh! Are you talking about those little Atmel boards? Yeah, they're pretty nice for learning tools. There's this engineer locally who's taking some real-time programming courses and he comes to me for tutoring. He has one of those. And it doesn't have a memory manager at all, I don't think. Of course, it only has a couple of K of RAM on it anyway. I'm not really sure what all it is able to do because I only ever see it when he comes to me for help with his assignments, and then I focus on his assignment and making sure he understands it since I'm charging him by the hour.
These days when I work at that level it is usually a DSP and I seldom run more than a multitasking executive in it along with my application. At that, I'm less interested in the DSP than in the signal processing I'm using the DSP for.
However, in the past, I've worked plenty of times in plenty of environments on the barest of bare metal. I've started machines by writing the bootstrap code, hand assembling it, and toggling it into the machine from the front-panel switches.
But these days? No one wants to pay me to do BIOS type work. They know I know it, but I'm much too expensive.
jiml8 is talking about the actual time that the program is executing on the CPU.
Sergei Steshenko is talking about actual elapsed time.
I'm not sure what the original poster's program is measuring but I believe that it is actual elapsed time.
jiml8 has said that there is a distinction between CPU time and actual elapsed time/wall clock time.
Sergei Steshenko is ignoring this distinction and talking about actual elapsed time issues.
It's pretty funny so far.
OP is indeed measuring wall clock time. As I understood his question, he didn't realize he was measuring wall clock time and wants to measure only the time the processor spends on that particular process.
Rather than belittle OP as some others have done, I chose to point out the issue and suggest where to look to deal with it.
Now, someone is trying to teach me how to suck eggs. I really don't think it is funny. I think it is sad. I can tell you that I wouldn't hire this person.
Nonsense. You are ignoring the fact that CPU knows nothing (at instructions level) about HW wait states and about the facts of it relinquishing the bus to higher priority masters.
Just what do you think an interrupt does??? Some of it is handled in firmware, some in software, and a small amount in silicon. But the processor is able to know about ALL of that.
another one told me 2 days ago: " it was possible to get accurate CPU time measurements on an ordinary machine, without setting any of the parameters for the kernel or requiring that the machine be otherwise unloaded.Unfortunately, that no longer seems to be possible with modern machines. The combination of hyperthreading and multicore processors means that a program may have many different execution and memory resources, depending on what other programs are running. The only reliable way to avoid this is to run a program in isolation. Also, we have found that the Intel Speedstep technology makes the timings from one run to another highly variable."
hope it helpful for discussion.
following is my sourcecode, in case that someone wants to exper... it.
#include<stdio.h>
int divisors(unsigned int n);
unsigned int antiprime(unsigned int x);
int main()
{
FILE *cin,*cout;
unsigned int n,res;
if(k == 1)//a prime greater than 31 or a number which is the product of some primes greater than 31. According to Zerle's theory, it is easy to prove that the current integer being checked is not benifit to the result, so it can be defined as 0 as the value to return.
return 0;
else
return k;
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.