我真的不想描述,因为我想要在不同的简单功能上做很多不同的小基准测试.对于我的生活,我找不到一种方法来记录C++中的毫秒数,顺便说一句,我正在使用Linux.
你能否建议以毫秒为单位获取系统时钟的方法(如果我找不到简单的方法,我可以用几秒钟来解决......)以及它们包含在哪个标题中?
我们在代码中使用计时器,我只是对它的实际实现感到好奇,是否有计时器
CPU逻辑电路或CPU外部,例如,外部时钟或类似的东西.
如果没有,那么地狱的计时器在哪里?请帮帮我,不需要任何详细的解释
如何制作硬件定时器,只需关注我们所拥有的硬件板上的定时器.
提前致谢 .
我知道有很多关于OV7670的互联网(例如http://forum.arduino.cc/index.php?topic=159557.0),我读了很多关于它的内容,但似乎缺少了一些内容.
首先,我看看我们如何从相机逐像素地读取以构建矩形600 X 480图像的方式,考虑到文档中描述的HREF,VSYNCH和PCLOCK,这很容易理解:http:/ /www.voti.nl/docs/OV7670.pdf.我理解XCLOCK是一个输入,我需要将OV7670作为一种循环控制器给出,RESET可以重置它.
所以在这一点上,我认为通过连接以下引脚可以覆盖这种相机的功能:
从我的角度来看,这种方法的实现类似于:代码:
for each loop function do
write high to XCLK
if VSYNCH is HIGH
return;
if HREF is LOW
return;
if lastPCLOCK was HIGH and currentPCLOCK is LOW
readPixelFromDataPins();
end for
Run Code Online (Sandbox Code Playgroud)
我readPixelFromDataPins()基本上只读了第一个字节(因为我只是测试我是否能从相机中读取内容),它的编写如下:
码:
byte readPixelFromDataPins() { …Run Code Online (Sandbox Code Playgroud) 试图用手模拟24小时时间的翻转(使用数学与使用时间跨度类).递增部分很容易弄清楚如何从23:00到0:00滚动,但从另一个方向走向结果却变得非常混乱.这是我到目前为止所拥有的:
static void IncrementMinute(int min, int incr)
{
int newMin = min + incr,
hourIncrement = newMin / 60;
//increment or decrement the hour
if((double)newMin % 60 < 0 && (double)newMin % 60 > -1)
hourIncrement = -1;
Console.WriteLine("Hour increment is {0}: ", hourIncrement);
}
Run Code Online (Sandbox Code Playgroud)
我发现的问题是当倒退时,如果模数在数字之间,它将不会正确递减.示例:它是12:00并且您减去61分钟,我们知道时间将是10:59,因为小时应该从12:00返回到11:59,然后从11:00返回到10:59 不幸的是我计算它的方式:在这种情况下newMin%60,只抓取第一个小时回滚,但由于第二次回滚在技术上是-1.0166作为余数,并且因为mod只返回一个整数,所以它四舍五入.我确定我在这里缺少一些基本的数学,但有人可以帮助我吗?
编辑:我已经写了很多长短的方法.有些比其他人更接近,但我知道这比看起来更简单.我知道这个似乎有点"他正在做什么",但你应该能够基本看到我想做的事情.增加时钟并使其从23:59到0:00翻转很容易.向后看已经证明并不那么容易.
好的,这是带翻转的incrementMinute.简单.但试着倒退.不行.
static void IncrementMinute(int min, int incr)
{
int newMin = min + incr,
hourIncrement = newMin / 60;
min = newMin % 60;
Console.WriteLine("The new minute is {0} and the hour …Run Code Online (Sandbox Code Playgroud) 所以,我有一个问题,我不完全理解需要给定时器命令的事件,它不会说在网上任何地方,我搜索了几个小时.所以我只是使用了大多数人似乎使用的'USEREVENT + 1'.我不确定它是否正确,但我的计时器无法正常工作.我正确使用它吗?这是我的代码:
nyansecond=462346
nyanint=0
spin=0
aftin=452345
def nyanmusic(nyansecond,nyanint,spin):
if nyanint == 0:
nyansound.play()
nyanint= 1
elif nyanint == 1:
nyansecond = pygame.time.set_timer(USEREVENT+1,7000)
if nyansecond < 200 and spin == 1:
spin = 0
nyansecond = pygame.time.set_timer(USEREVENT+1,7000)
elif nyansecond > 6500 and nyansecond < 100000 and spin == 0:
spin = 1
nyansoundm.play()
return nyansecond,nyanint,spin
Run Code Online (Sandbox Code Playgroud)
然后我在我实现的第二页上将其定义为我的代码(工作正常).它运行nyansound,但在6.5秒(6500毫秒)后不运行nyansoundm.我正在制作这个程序,以帮助我学习python和pygame的基础知识,然后继续学习更复杂的东西.当我想听nyan cat或其他环状歌曲而不必去youtube并浪费宝贵的带宽时,我也可以使用它.不过不要担心.
哦,这是我放入循环的代码,虽然我不认为这太重要了:
#music
nyansecond,nyanint,spin = nyanmusic(nyansecond,nyanint,spin)
Run Code Online (Sandbox Code Playgroud) 我的目的是在while规定的时间内执行循环(例如,本例中为90秒).它不一定是90秒,但1-2秒的不准确是可以接受的.为了这个目的,我试图使用clock()`函数:
int main(void){
clock_t start, end;
volatile double elapsed;
start = clock();
int terminate = 1;
while(terminate)
{
end = clock();
elapsed = ((double) (end-start)) / (double) CLOCKS_PER_SEC *1000;
printf("elapsed time:%f\n",elapsed);
if(elapsed >= 90.0)
terminate = 0;
usleep(50000);
}
printf("done..\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我在我的笔记本电脑上运行它(x86,3.13内核,gcc 4.8.2)时,我的秒表测量它完成72秒.(1000 elapsed我的笔记本电脑必须具有几秒钟的准确度)
当我在ARM设备(armv5tejl,3.12内核,gcc 4.6.3)上运行它时,需要58秒才能完成代码.(我需要使用100上elapsed对的ARMv5).
我在室温下运行代码,因此时钟应该稳定.我知道内核会休眠线程,并且有时间不准确地唤醒它们等等.因此,正如我之前所说,我不希望得到一个完美的时序,但它应该有一些准确性.
我曾试图只使用usleep(偶数nanosleep),但分辨率也不好.最后,我想出了获取系统时间(小时,分钟,秒)的底部代码,然后计算经过的时间.并且它具有良好的准确性.
我想知道是否有另一种解决方案使用成本更低?
typedef struct{
int hour;
int minute;
int second;
} timeInfo;
timeInfo getTimeInfo(void){
timeInfo value2return; …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Wear模拟器上使用新的watch face API,当我扩展CanvasWatchFaceService时,onTimeTick方法从未被触发,因此时钟从未更新过.
我正在使用模拟样本并尝试删除秒针(暂时禁用计时器):
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR …Run Code Online (Sandbox Code Playgroud) 我有这个javascript代码,应该显示时间.有用.我不想增加额外的时间.可以说我想加1个小时.
<script type="text/javascript">
Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + (h*60*60*1000));
return this;
}
// This function gets the current time and injects it into the DOM
function updateClock() {
// Gets the current time
var now = new Date();
// Get the hours, minutes and seconds from the current time
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
// Format hours, minutes and seconds
if (hours < 10) {
hours = "0" + hours;
}
if …Run Code Online (Sandbox Code Playgroud) 我试图通过使用物理时钟来测量c ++中某些命令的执行时间,但是我遇到了一个问题,即从计算机上的物理时钟读取测量值的过程可能需要很长时间.这是代码:
#include <string>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <time.h>
int main()
{
int64_t mtime, mtime2, m_TSsum, m_TSssum, m_TSnum, m_TSmax;
struct timespec t0;
struct timespec t1;
int i,j;
for(j=0;j<10;j++){
m_TSnum=0;m_TSsum=0; m_TSssum=0; m_TSmax=0;
for( i=0; i<10000000; i++) {
clock_gettime(CLOCK_REALTIME,&t0);
clock_gettime(CLOCK_REALTIME,&t1);
mtime = (t0.tv_sec * 1000000000LL + t0.tv_nsec);
mtime2= (t1.tv_sec * 1000000000LL + t1.tv_nsec);
m_TSsum += (mtime2-mtime);
m_TSssum += (mtime2-mtime)*(mtime2-mtime);
if( (mtime2-mtime)> m_TSmax ) { m_TSmax = (mtime2-mtime);}
m_TSnum++;
}
std::cout << "Average "<< (double)(m_TSsum)/m_TSnum
<< " +/- " << …Run Code Online (Sandbox Code Playgroud) 我一直在寻找这个问题的答案,但还没有明确的文档。
来自手册页说它受到NTP执行的增量调整CLOCK_MONOTONIC的影响clock_gettimeadjtime
时钟单调
Run Code Online (Sandbox Code Playgroud)Clock that cannot be set and represents monotonic time since some unspecified starting point. This clock is not affected by discontinuous jumps in the system time (e.g., if the system administrator manually changes the clock), but is affected by the incremental adjustments performed by adjtime(3) and NTP
我不清楚的是它是受到NTP所做的各种调整的影响还是只是小调整的影响?
假设 NTP 发生较大的时间跳跃,如果系统偏离时钟,会CLOCK_MONOTONIC反映出来吗?
我不确定 NTP 使用以下哪个系统调用来调整我的 Cent OS 系统上的时间
快速测试表明,尽管 NTP 使系统跳跃了 10 个小时,但单调时钟输出没有变化。
即使通过调用使时间跳跃clock_settime也不会影响单调时间