Tag: 时钟

软件用于Windows操作系统的C中断服务程序

#include #include #include void Task() { printf(“Hi”); } int main ( ) { time_t t; clock_t start, end; long i; long count; double x = 0.0; count = 2; start = clock(); time(&t); printf(ctime(&t)); printf( “Counting to %ld\n”, count ); if(count) { Task(); } end = clock(); printf( “That took %f seconds and I counted […]

C时钟:时间点亮

对于学校我必须做一个任务,我现在忙着它已经有3个星期了,但仍然没有走得太远。 我们需要制作一个必须是圆形的时钟,并且需要点亮秒数和小时的颜色。 所以,如果是凌晨4点25分,这些数字需要点亮。 这就是我现在所拥有的: #include #include #include #include #include #include int csecs (int cseconds ); void main (int sec, int min){ printf(“Hallo! Veel plezier met het bekijken van de tijd!”); getch(); while (sec) { time_t cseconds; cseconds = time (NULL); printf (“De Tijd: “); printf (“%d:”, csecs( cseconds )/60/60%24+1); printf (“%d:”, csecs( cseconds )/60%60 ); […]

Android和JNI实时时钟

我遇到了迷你Android应用程序的问题以及在C(JNI)函数中使用实时时钟信号。 看起来Android UI不喜欢来自C函数中实例化的定时器的实时信号。 在下面的PoC ,定时器每秒触发信号5次,如果在UI更新时触发信号,则应用程序崩溃。 如果我没有启动计时器=>没有崩溃 如果我没有在UI上放任何东西=>没有崩溃 我写了这个小PoC来certificate这种行为。 Java部分只是调用JNI函数并在屏幕上放置一个按钮。 public class MainActivity extends AppCompatActivity { Button bt; static { System.loadLibrary(“testtimer-jni”); } /* JNI ingresso */ public native void jniStartTimer(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); jniStartTimer(); /* load button */ bt = new Button(getBaseContext()); setContentView(bt); } } 这是main.c文件的内容。 实例化并启动计时器。 每200ms (每秒5次cb()调用cb()函数。 #include #include #include […]

clock() – c函数的执行时间

我试图用C来衡量代码块的执行时间。我的代码中有这样的东西: clock_t begin, end; double time_spent; begin = clock(); ATL_dsymv(122,n,alfa,A,n,X,1,beta,Y,1); end = clock(); time_spent = (double)(end – begin) / CLOCKS_PER_SEC; printf (“(%f seconds)”,time_spent); 但它总是返回:(0.000000秒)。 我在更简单的代码块上尝试了同样的事情,但是它有相同的结果。 我究竟做错了什么? 非常感谢。

使用RDTSC以C计算CPU频率始终返回0

我们的讲师给出了以下代码,因此我们可以测量一些算法性能: #include #include static unsigned cyc_hi = 0, cyc_lo = 0; static void access_counter(unsigned *hi, unsigned *lo) { asm(“rdtsc; movl %%edx,%0; movl %%eax,%1” : “=r” (*hi), “=r” (*lo) : /* No input */ : “%edx”, “%eax”); } void start_counter() { access_counter(&cyc_hi, &cyc_lo); } double get_counter() { unsigned ncyc_hi, ncyc_lo, hi, lo, borrow; double result; access_counter(&ncyc_hi, […]

理解clock_gettime()的不同时钟

嗨,我想使用clock_gettime()函数来测量我的代码的性能。 我无法理解手册页描述中函数中使用的各种时钟之间的区别。 ESP CLOCK_REALTIME, CLOCK_PROCESS_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID 有人可以解释每个钟表的作用吗?

C ++:Linux中的时序(使用clock())不同步(由于OpenMP?)

在程序的顶部和末尾,我使用clock()来计算程序完成所需的时间。 不幸的是,它的报告时间似乎只有一半。 我用“time”命令仔细检查了这一点。 我的计划报告:在45.86s完成 时间命令报告:实际0m22.837s用户0m45.735s sys 0m0.152s 使用我的手机计时,它在23秒完成(又名:“真正的”时间)。 “用户”时间是所有线程的总和,这在我使用OpenMP之后才有意义。 (您可以在这里阅读: ‘真实’,’用户’和’sys’在时间(1)的输出中是什么意思? ) 那么,为什么clock()报告的是“用户”时间而不是“真实”时间? 我应该使用不同的函数来计算程序运行的时间吗? 作为旁注,Windows的clock()按预期工作,并在“实际”时间内报告。

C`clock()`函数只返回零

C clock()函数只返回零。 我尝试使用不同的类型,没有任何改进……这是一个很好的精确测量时间的方法吗? #include #include int main() { clock_t start, end; double cpu_time_used; char s[32]; start = clock(); printf(“\nSleeping 3 seconds…\n\n”); sleep(3); end = clock(); cpu_time_used = ((double)(end – start)) / ((double)CLOCKS_PER_SEC); printf(“start = %.20f\nend = %.20f\n”, start, end); printf(“delta = %.20f\n”, ((double) (end – start))); printf(“cpu_time_used = %.15f\n”, cpu_time_used); printf(“CLOCKS_PER_SEC = %i\n\n”, CLOCKS_PER_SEC); return […]

更快相当于gettimeofday

在尝试构建一个对延迟敏感的应用程序时,需要每秒发送100条消息,每条消息都有时间字段,我们要考虑优化gettimeofday。 首先想到的是基于rdtsc的优化。 有什么想法吗 ? 还有其他指针吗? 返回的时间值所需的精确度以毫秒为单位,但如果该值偶尔与接收器不同步1-2毫秒则不是很大。 试图比62纳秒的gettimeofday做得更好