digitalmars.D.learn - Question on rewrite boost.timer with D2.031
- Sam Hu (69/69) Jul 20 2009 Sorry for it is a bit long...
Sorry for it is a bit long... As an exercise,I was tring to rewrite boost.timer ,boost.progress and the timer_test.cpp program accompany with the boost doc in D2.Although it works now,I compared the two result of the timer_test.cpp & timer_test.d and I found the timing result is quite different when they are running.Attached both boost version & D2 version sources and test program.Below is the summary of the 2 version program running result: ============== C++ boost: timer::elapsed_min() reports 0.001 seconds timre::elapsed_max() reports 2.14748e+006 seconds,which is 596.523 hours verify progress_display(0) doesn't divide by zero 0% 10 20 30 40 50 60 70 80 90 100% |----|----|----|----|----|----|----|----|----|----| *************************************************** determine 1 second iteration count 8137014 iterations burn about 1seconds 0% 10 20 30 40 50 60 70 80 90 100% |----|----|----|----|----|----|----|----|----|----| *************************************************** burn about 1 seconds again 0% 10 20 30 40 50 60 70 80 90 100% |----|----|----|----|----|----|----|----|----|----| *************************************************** Leading string 1 0% 10 20 30 40 50 60 70 80 90 100% Leading string 2 |----|----|----|----|----|----|----|----|----|----| Leading string 3 *************************************************** t1 elapsed: 2.013 t2 elapsed:2.013 t3 elapsed:1.011 t4 elapsed:1.011 t5 elapsed:1.011 t1 and t2 should report the same time (very approximately 2 seconds). t3,t4 and t5 should report about the same time, The following elapsed time should be slightly greater than t1. 2.01 s ======================== D2 version: timer.elapsed_min() reports 0.001000 seconds. timer.elapsed_max() reports 2147483.647000 seconds,which is 596.52 hours verify progress_display(0) doesn't divided by zero 0% 10 20 30 40 50 60 70 80 90 100% |----|----|----|----|----|----|----|----|----|----| *************************************************** determine 1 second iteration count 19044248 iterations burn about 1 seconds. 0% 10 20 30 40 50 60 70 80 90 100% |----|----|----|----|----|----|----|----|----|----| ************************************************** burn about 1 seconds again 0% 10 20 30 40 50 60 70 80 90 100% |----|----|----|----|----|----|----|----|----|----| ************************************************** Leading string 10% 10 20 30 40 50 60 70 80 90 100% Leading string 2|----|----|----|----|----|----|----|----|----|----| Leading string 3*************************************************** t1 elapsed:2.524000 t2 elapsed:2.524000 t3 elapsed:1.272000 t4 elapsed:1.272000 t5 elapsed:1.272000 t1 and t2 should report about the same times (very approximately 2 seconds t3,t4 and t5 should report the same times, and these should be about half the t1 and t2 times. The following elapsed time should be slightly greater than t1. 2.52 seconds elapsed so far. ==================================== After running many times,although each time the result varies,I can still see C++ boost version generates very approximate to 2 seconds,say,2.013 seconds. While the D2 one is quite larger,say,2.524 seconds. So my questions are, is there anything I did wrong in D2 version,or re-implement such a timer in D2 using the same mechanism does not make sense. It would be grateful if anybody can figure me out the clue. Regards, Sam
Jul 20 2009