![]() |
|
#1
|
|||
|
|||
Strange clock behavior when using GMPI have just started using GNU MP (the bignum library), and I've been experiencing some strange behaviour when using the clock. I set up a quick program to calculate the time it takes to calculate every factorial from i=1 to 500, and it runs quite quickly (about 3 seconds), however, it always returns 0 elapsed time. My code is...
CPP / C++ / C Code:
When I run it, I get (just the last few lines)... ....0692636533817505547812864000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 000 = 500! clocks per sec: 1000000 start: 0 end: 0 If I use the code on another program that doesn't use GMP, everything seems to work fine. Does anyone know why I would be getting 0 for my start and end time? What am I missing here? Is there something in particular that I must do to get this to work when using the GMP library? Also, to compile, I execute: g++ factorialtest.cpp -lgmpxx -lgmp Thanks for the help! |
|||
|
#2
|
|||
|
|||
Re: strange clock behavior when using GMPQuote:
Bottom line: do you really want elapsed time? Or do you want process time? What operating system/compiler are you using? If you want elapsed time: If it's GNU/Linux with gcc, do a "man gettimeofday" to see how to measure elapsed time. Or just execute "time progname" from a command line and you will see system time and elapsed time. To get a significant amount system time, you might do something like calculate 10000 factorial (maybe more if your system is really fast). Use gettimeofday() before and after the calculation (but before the printout). Compare with the command line "time progname," and compare with your clock() method Regards, Dave |
|
#3
|
|||
|
|||
Re: Strange clock behavior when using GMPThanks for the help Dave! It makes a lot more sense now... I didn't realize how much longer it took to display the result than it took to actually calculate it. I've changed the code up a bit (so now it only calculates a single factorial), so here it is now...
CPP / C++ / C Code:
I have the clock() calculating total time (including time to display the factorial), and the gettimeofday() calculating only calculation time. Here are the results for calculating 200000!, including the return from using "time progname". ....0000000 = 200000! clocks per sec: 1000000 start in clock: 0 end in clock: 1140000 Time from clock(): 1.14 Time from gettimeofday(): 0.252494 real 0m3.957s user 0m1.144s sys 0m0.009s It's interesting that the clock() calculated time is close to the "user" time, but the gettimeofday() isn't represented in any of the numbers returned from executing "time progname". I wonder what the "sys" time means? Thanks again for the help! |
|
#4
|
|||
|
|||
Re: Strange clock behavior when using GMPI just removed the part of the program that displays the factorial result, and things seem to line up much better (in terms of time). This is what I get with no display of the factorial....
clocks per sec: 1000000 start in clock: 0 end in clock: 240000 Time from clock(): 0.24 Time from gettimeofday(): 0.249288 real 0m0.252s user 0m0.246s sys 0m0.006s ...interesting |
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Click Ticks | dayrinni | C Programming Language | 1 | 20-Feb-2006 12:50 |
| Strange C++ code memory leakage problem | gaoanyu | C++ Forum | 7 | 04-Nov-2005 09:09 |
| FLTK clock box widget | cable_guy_67 | FLTK Forum | 0 | 09-Jul-2005 19:51 |
| Computer Clock Problem | kselin | Computer Hardware Forum | 7 | 21-Jun-2005 09:26 |
| Strange behaviour in printf (interesting) | nusstu | C Programming Language | 9 | 05-Apr-2004 14:36 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The