July 11, 2021

On 7/9/21 5:13 PM, rempas wrote:

>

On Friday, 9 July 2021 at 20:54:21 UTC, Paul Backus wrote:

>

On Friday, 9 July 2021 at 20:43:48 UTC, rempas wrote:

>

I'm reading the library reference for core.time and It says that the duration is taken in "hnsecs" and I cannot understand if we can change that and choose the precision. Does anyone know if we can do that?

It is stored internally in "hnsecs", but you can convert it to other units using the total method [1]; for example, myDuration.total!"nsecs".

[1] https://dlang.org/phobos/core_time.html#.Duration.total

It doesn't work for me. I have the following code:

MonoTime start = MonoTime.currTime();
// Doing stuff
MonoTime end = MonoTime.currTime();
Duration dur = end - start;
dur = dur.total!"nsecs";

and I get the following error message:

"Error: cannot implicitly convert expression `dur.total()` of type `long` to `Duration`"

BTW Duration is truncating here. MonoTime stores its values in implementation-defined ticks, which can be nanoseconds or any other thing that the specific clock uses. Whereas Duration uses strictly hnsecs.

If you want to get sub-hnsec resolution, use the ticks member of MonoTime and ticksPerSecond and do the math for the units.

See the warning here.

-Steve

July 13, 2021

On Friday, 9 July 2021 at 20:43:48 UTC, rempas wrote:

>

I'm reading the library reference for core.time and It says that the duration is taken in "hnsecs" and I cannot understand if we can change that and choose the precision. Does anyone know if we can do that?

don't expecting 1ns when you running software on GHz clocking CPU running with normal-linux.

1ns means 1Ghz. and common x86 cpu runs at 1-4Ghz, and in this situation, only 10ns will be expected from base-metal software(OS). as normal-linux is not real-time at all, 100ns is logical.

thanks!

dbh.

1 2
Next ›   Last »