Question on rewrite boost.timer with D2.031

Sam Hu samhudotsamhu at gmail.com
Mon Jul 20 21:17:10 PDT 2009


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: timer.hpp
Type: application/octet-stream
Size: 2734 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20090721/510c91ad/attachment-0006.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: progress.hpp
Type: application/octet-stream
Size: 5652 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20090721/510c91ad/attachment-0007.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: timer_test.cpp
Type: application/octet-stream
Size: 2816 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20090721/510c91ad/attachment-0008.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: timer.d
Type: application/octet-stream
Size: 567 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20090721/510c91ad/attachment-0009.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: progress.d
Type: application/octet-stream
Size: 1951 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20090721/510c91ad/attachment-0010.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: timer_test.d
Type: application/octet-stream
Size: 2055 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20090721/510c91ad/attachment-0011.obj>


More information about the Digitalmars-d-learn mailing list