在C++中尽可能接近30ms退出循环的最佳方法是什么.轮询提升:microsec_clock?轮询QTime?别的什么?
就像是:
A = now;
for (blah; blah; blah) {
Blah();
if (now - A > 30000)
break;
}
Run Code Online (Sandbox Code Playgroud)
它应该适用于Linux,OS X和Windows.
循环中的计算用于更新模拟.每隔30ms,我想更新视口.
我一直在自学JavaScript,我还是比较新的,我试图将时钟功能添加到我的网站,但是,我看不到要显示它,这是我的完整代码:
<html>
<head>
<script type="text/javascript">
function tick() {
var hours, minutes, seconds, ap;
var intHours, intMinutes, intSeconds;
var today;
today = new Date();
intHours = today.getHours();
intMinutes = today.getMinutes();
intSeconds = today.getSeconds();
if (intHours == 0) {
hours = "12:";
ap = "Midnight";
} else if (intHours < 12) {
hours = intHours + ":";
ap = "a.m";
} else if (intHours == 12) {
hours = "12:";
ap = "noon";
} else {
intHours = intHours - 12
hours …Run Code Online (Sandbox Code Playgroud) 我要疯了吗?我在 x86_64 上运行它。
#include <stdio.h>
#include <time.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
printf("Clock: %f\n", clock() / (double)CLOCKS_PER_SEC);
sleep(1);
printf("Clock: %f\n", clock() / (double)CLOCKS_PER_SEC);
sleep(1);
printf("Clock: %f\n", clock() / (double)CLOCKS_PER_SEC);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这打印
时钟:0.002880
时钟:0.002968
时钟:0.003019
它显然在线路上等待了一秒钟sleep(1),但输出显然是错误的。
如果这不起作用,是否有可移植的 C 替代方案?
这是一个带有迭代Fibonacci的C程序,使用clock()来计算获得第n个Fibonacci数所需的时间.程序循环不停.我知道方程是正确的,因为我能够在没有时钟功能的情况下正确运行程序.任何帮助表示赞赏!
#include<time.h>
#include<sys/file.h>
#include<stdio.h>
int main ( )
{
int j=1, fib, n, i=1, k=0;
int choice;
float x,y,z;
x = clock(); //start clock
printf("input the fib number you want: ");
scanf("$d", &n);
while (k <=n)
{
fib = i + j;
i = j;
j = fib;
++k;
printf( "The fib number is %d\n ", fib);
}
y =clock(); // end clock
z = (y - x) / CLOCKS_PER_SEC;
printf("\n\nThe execution time was: %.15f", z);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 有没有办法通过使用python模块访问从任何特定的原子钟网站给出的时间?
我不是在寻找极端的准确性.我正在寻找一种方法来确保我的程序获得正确的时间,以防用户的CPU时间不正确.
我搜索了python 3模块索引并找到了时间模块但没有提到原子钟.
我也看了谷歌并发现了一些提及,但没有任何当前的,这可能是有用的.
编辑:感谢大家的信息.我想我只需要确保用户时钟是正确的或让他们确保它.也许我可以在用户启动程序时检查原子钟,然后如果他们的时钟关闭一定量,显示一个弹出窗口,让他们知道时间的差异,并给他们一个选项来禁用弹出窗口.
谢谢!扎克
在 linux 中获取时间戳与 linux 的时钟周期相同。我知道如何获取时间戳,但我现在不知道如何以滴答为单位获取时钟周期。有人能告诉我这两者有什么区别吗??有人能给我一个关于时钟周期的小例子吗?
期待您的回复。
额外:我正在尝试使用简单标量模拟器在 pisa 架构中添加用于计时的汇编指令。对于我的指令,我应该访问时钟周期并将其存储在寄存器中。
如何创建一个带有php的活动时钟从服务器获取时间而不是用户pc时间[不是javascript]
我使用下面的代码,但使用PHP变量时停止
<form name="Tick">
<input type="text" size="12" name="Clock">
</form>
<script type="text/javascript">
function show(){
var hours="<?php echo $myhour; ?>"
var minutes="<?php echo $mymin; ?>"
var seconds="<?php echo $mysec; ?>"
var dn="AM"
if (hours>12){
dn="PM"
hours=hours-12
//this is so the hours written out is in 12-hour format, instead of the default //24-hour format.
}
if (hours==0)
hours=12
//this is so the hours written out when hours=0 (meaning 12a.m) is 12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
document.Tick.Clock.value=
hours+":"+minutes+":"+seconds+" "+dn
setTimeout("show()",1000)
}
show() …Run Code Online (Sandbox Code Playgroud) 我知道你可能会将此标记为重复,但兄弟主题都没有解决我的问题,所以这是我简单的日期倒计时指令:
class Clock {
constructor() {
this.restrict = 'AC';
this.replace = true;
this.template = require('./templates/clock.tpl.html');
this.scope = {};
}
link(scope, elem, attrs, $interval) {
let end = new Date('05/05/2017 9:00 AM');
let _second = 1000;
let _minute = _second * 60;
let _hour = _minute * 60;
let _day = _hour * 24;
scope.showRemaining = () => {
let now = new Date();
let distance = end - now;
let days = Math.floor(distance / _day);
let hours = Math.floor((distance % …Run Code Online (Sandbox Code Playgroud) 您是否知道 Linux 用户空间中高分辨率时钟(最小微秒)的任何 C/C++ 实现(即使它不可移植)?
目标是测量一些低延迟操作的时间间隔。我测量到内核空间时钟有时会导致延迟峰值。
根据我对 Red Hat 7.2 的研究:
谢谢。