- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要将此 C 代码移植到 Rust 中:
QueryPerformanceFrequency((unsigned long long int *) &frequency);
struct timespec now;
if (clock_gettime(CLOCK_MONOTONIC, &now) == 0)
frequency = 1000000000;
std::time::Instant::now()
并将频率设置为 1000000000?
// Initializes hi-resolution MONOTONIC timer
static void InitTimer(void)
{
srand(time(NULL)); // Initialize random seed
#if defined(_WIN32)
QueryPerformanceFrequency((unsigned long long int *) &frequency);
#endif
#if defined(__linux__)
struct timespec now;
if (clock_gettime(CLOCK_MONOTONIC, &now) == 0)
frequency = 1000000000;
#endif
#if defined(__APPLE__)
mach_timebase_info_data_t timebase;
mach_timebase_info(&timebase);
frequency = (timebase.denom*1e9)/timebase.numer;
#endif
baseTime = GetTimeCount(); // Get MONOTONIC clock time offset
startTime = GetCurrentTime(); // Get current time
}
最佳答案
访问 Windows API 的直接解决方案是使用 winapi
箱。在这种情况下,请调用 QueryPerformanceFrequency
:
use std::mem;
use winapi::um::profileapi::QueryPerformanceFrequency;
fn freq() -> u64 {
unsafe {
let mut freq = mem::zeroed();
QueryPerformanceFrequency(&mut freq);
*freq.QuadPart() as u64
}
}
fn main() {
println!("Hello, world!");
}
[dependencies]
winapi = { version = "0.3.8", features = ["profileapi"] }
hi-resolution MONOTONIC timer
Instant
作为一个单调的计时器,并假设它的精度足够高,直到证明不是这样。
关于windows - 如何将调用 QueryPerformanceFrequency 的代码移植到 Rust?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60851597/
我需要将此 C 代码移植到 Rust 中: QueryPerformanceFrequency((unsigned long long int *) &frequency); 我没有找到这样做的功能。
每当我打电话时: std::chrono::high_resolution_clock::now().time_since_epoch().count(); 它的组装说明是: std::chrono:
从这些看来,函数返回以赫兹为单位的值 QueryPerformaceFrequency() Units of QueryPerformanceFrequency 运行英特尔酷睿 i5 - 以 2.8
MSDN 上有一篇文章谈到QueryPerformanceCounter: Acquiring high-resolution time stamps 底部是常见问题解答部分,其中有一个有趣的问题:
我正在研究 QueryPerformanceFrequency。它过去常常返回 3.6 Mhz,但这对于我尝试做的事情来说还不够。 我已使用此命令启用 HPET bcdedit/set useplat
我与 FAA 有一个长期计划,在 FAA 开始部署 Dell GX-760 台式机之前一直运行良好。该程序是空中交通的图形重播。我使用 QueryPerformanceFrequency 函数来获取处
它们都提供毫秒分辨率吗? 最佳答案 不,它们没有毫秒精度。 clock 和 GetTickCount 在大多数系统上具有 4 到 15 毫秒的精度。 QueryPerformanceCounter 的
这个想法是现有项目非常频繁地使用 timeGetTime()(针对 windows 目标)。 milliseconds = timeGetTime(); 现在,这可以替换为 double tmp =
我在各种操作系统上运行一些计时代码。我注意到 QueryPerformanceCounter 的结果有以下模式 标准 Windows XP 使用处理器频率,这意味着它在后台使用 RDTSC。 Vist
我一直在将我的游戏从 C++ 转换为 C#。我很好奇计时器将如何在 C# 缺少 QueryPerformanceFrequency() 和 QueryPerformanceCounter() 的情况下
我是一名优秀的程序员,十分优秀!