| giszzmo (22) | |||
I cant figure out how to make this into microseconds. What I have just does seconds.
Thanks, giszzmo | |||
|
Last edited on
|
|||
| Albatross (3551) | |
|
Why not just remove a certain large number from line 8? -Albatross | |
|
|
|
| giszzmo (22) | |
| I still don't get microseconds. | |
|
|
|
| Angeljruiz (169) | |||
Heres an example of clock
| |||
|
|
|||
| giszzmo (22) | |
|
What does this mean: "The number of primes lower than 100,000 is: %d\n",f);" Why 100,000? There are 1,000,000 microseconds in a second. Thanks! | |
|
|
|
| Cataclysm31536 (2) | |
|
Is the computers clock accurate for microseconds? I'm sure it is, but can the program operate that? | |
|
|
|
| Stewbond (1842) | ||||
|
giszzmo, ignore the 100,000... that's how many numbers he was checking in his frequency of primes function. If you increase that number, it'll increase the computational time. Computer clocks are generally not accurate to the micro-second. <time.h> or <ctime> doesn't have a high-resolution timer that can get this accurate. To get something with a very high resolution, you need to use something directly from your operating system. The resolution that you will get will depend on your hardware (if your processor runs at 1 GHz (1 tick per microsecond) you will not have 1 micro-second resolution). Here's an example of something high-res for windows with an output from my system. (It also demonstrates how inaccurate the Sleep() function is).
Edit: Machine is running at 3.33 MHz. The timer resolution here is 0.30 microseconds. | ||||
|
Last edited on
|
||||
| cire (2347) | |||
If your compiler has std::chrono, this adaptation of Angeljruiz's code may serve.
http://www.informit.com/articles/article.aspx?p=1881386&seqNum=2 may be found useful. | |||
|
|
|||
| giszzmo (22) | |
| Would converting it to milliseconds be easier? | |
|
|
|
| Stewbond (1842) | |
Not really. It just means that you'd go from this: (end.QuadPart - start.QuadPart) * 1000000 / freq.QuadPart to this (end.QuadPart - start.QuadPart) * 1000 / freq.QuadPart Unless you cast that division to a double, you'll still get integer division and you won't have the decimal points. If you don't mind 1-second resolution, then you can use the <ctime> header/library. | |
|
|
|
| ne555 (4383) | |
|
> Computer clocks are generally not accurate to the micro-second. They are. > To get something with a very high resolution, you need to use something directly from your operating system. ¿And where will the OS get that info from? > 1 GHz (1 tick per microsecond) 1GHz = 1e9 Hz. That means 1 tick every 1e-9 s (one nanosecond), so 1000 ticks per microsecond However, clock() does not count ticks > Machine is running at 3.33 MHz. ¿steam powered? @OP: clock() measure the time that your program is executing, using `clocks' units CLOCKS_PER_SEC tells you how many `clocks' are in 1 second | |
|
Last edited on
|
|
| Stewbond (1842) | |
| C'mon ne555. stop being a jerk. So I mixed GHz with MHz. That also didn't change the fact that my 3.4Ghz i7 is running at 3.33MHz on electricity (not steam). It also doesn't make my code or output in any way-shape-or-form wrong. | |
|
Last edited on
|
|
| ne555 (4383) | |
|
zo'o you may be running out of coal. timer_resolution \neq cpu_speed | |
|
|
|