Ada中微秒数的计算
在 C 语言中,我们有 get_usec(),它为我们提供自当前秒开始以来的微秒数。 -说到“当前秒”必然指的是时间参考,通常是 EpochTime。 -在 Ada.Calendar 包中,我通过示例看到了秒或时钟功能,并且能够分割和显示时间。获取秒数。 但是如何获取自当前秒开始以来的微秒数呢? 谢谢 标记
in C langage we have get_usec() which gives us the number of microseconds since the start of the current second.
-Speaking of the "current second" necessarily refers to time reference which is often EpochTime.
-In Ada.Calendar package, I see Seconds or Clocks functions by example with ability to split & get the seconds.
But how to get the number of microseconds since the start of the current second, please?
Thanks
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Ada.Calendar 和 Ada.Calendar.Formatting 包提供了您需要的信息。
该程序一次执行的输出为:
自当前秒起的亚秒数:0.655316600
在此执行中,值指示 655316.6 微秒。
The packages Ada.Calendar and Ada.Calendar.Formatting provide the information you will need.
The output of one execution of this program is:
Sub seconds since current second: 0.655316600
In this execution the value indicated 655316.6 microseconds.
请注意,Ada.Calendar 适用于当地时间,并且可能会向后跳转。如果它可用(是否有任何 83 后编译器不提供它?),您最好使用 Ada.Real_Time ARM D.8:
现在 Count 包含自纪元以来的整秒数,而 Sub 包含除了计数之外还有一秒。 Ada.Real_Time.To_Duration 将 Time_Span 转换为 Duration,允许您将其乘以 1E6 以获得微秒。
Note that Ada.Calendar is for local time, and may jump backwards. If it's available (are there any post-83 compilers that don't provide it?), you'll be better off using Ada.Real_Time ARM D.8:
Now Count contains the number of whole seconds since the epoch and Sub contains the fraction of a second in addition to Count. Ada.Real_Time.To_Duration converts a Time_Span to Duration, allowing you to multiply it by 1E6 to get microseconds.
当然,也可以在没有 Ada.Calendar.Formatting 的情况下完成,例如:
结果以亚秒为单位。
但据我所知,使用 Ada.Calendar.Formatting.Sub_Second 更短,并且可能更好(更快或更准确);我没有比较这两种方法。
It can also be done (of course) without Ada.Calendar.Formatting, like this for example:
with the result in Subsec.
But using Ada.Calendar.Formatting.Sub_Second is shorter, and may be better (faster or more accurate) for all I know; I did not compare the two methods.
非常感谢您的回答。
使用你所有的例子,我做了一些尝试,如下:
Many thaks for yours answers.
Using all yours examples, i made some trials, one is below :
您可以使用一个肮脏的技巧,定义一条记录 My_raw_duration_Type :whole_part、fraction_part,均为 U32。定义 Unchecked_Conversion To_Raw (Ada.Real_Time.Duration, My_Raw_Duration_Type)。然后获取结果并将其命名为 My_Raw_Duration。您想要的毫秒结果是integer(float(My_Raw_Duration.Fraction_Part)/float(4*1032**2) * 1000.0);
You can do a dirty trick where you define a record My_raw_duration_Type : whole_part, fraction_part, both U32. Define Unchecked_Conversion To_Raw (Ada.Real_Time.Duration, My_Raw_Duration_Type). Then take the result of that and call it My_Raw_Duration. The milliseconds result you want is integer(float(My_Raw_Duration.Fraction_Part)/float(4*1032**2) * 1000.0);