双时钟实验 [英] Double Clock Experiment

查看:84
本文介绍了双时钟实验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下实验是TIME TRAVEL的演示。当写这个程序并测试它时,我发现有时候

程序会参与时间旅行,但有时它会参与
不。仔细测试和重新编程后,我已经优化了代码

所以它应该每次都有效,但我建议你在运行时离开

房间并想一想其他的。这需要大约5

小步车才能运行,所以如果你不盯着空白屏幕会更好。


这是双时钟实验的方法经营:


程序循环如下:


LOOP


等待


a = a +时间


等待


b = b +时间


GOTO LOOP


c =时间


然后检查a和b之间的差异是否正确

与c相比。在正常的物理学中它应该是,但如果程序时间

旅行,那么输出将是不同的。告诉你我的意思

让我给你一个运行程序的例子:


等待10


a = a +时间10


等待10


b = b +时间20


等待10


a = a +时间30

等待10


b = b +时间40


等待10


a = a +时间50

等待10


b = b +时间60

-


现在A = 90& B = 120


-最近检查时间 -


C =时间60


使用逻辑我们可以推断出A应该比C / 2小于
B,但是当你运行程序时,时间差异可以在任何一个方向上显着变化
。最重要的是,

运行程序所需的时间也不是一成不变的。我们可以得出什么结论




我会告诉你一些示例输出然后给你来源:


时间A:146124514

时间B:146270790

时间C:293157


C / 2 = 146578.5

实际差异145276


时间A未来是1302.6,或者时间b是1302.6

进入过去。


这是一些更实际的输出:


时间A:144371012

时间B:144515341

时间C:289188

C / 2 = 144594

实际差价:144329


时间A未来有265个嘀嗒声,或者时间b为265蜱进入

过去。


我希望我有一个原子钟来试验,但这里是

来源:


#include< sys / types.h>

#include< time.h>

#include< unistd.h>

#include< stdio.h>

#include< math.h>


int main()

{


clock_t c0,c1,c2; / * clock_t在< time.h>上定义。和

< sys / types.h> as int * /

长计数;

printf(使用UNIX函数时钟测量CPU时间...... \ n);

count = 0; count< 1000; count ++){


for(int cnt1 = 0; cnt1< 100000; cnt1 ++){

c1 =时钟();

}


c0 = c0 + clock();


for(int cnt2 = 0; cnt2< 100000; cnt2 ++){

c1 = clock();

}


c2 = c2 + clock();


}


c1 = clock();


printf(" \tend(CPU);%d \ n",(int)c0);

printf(" \tend(CPU2);%d \ n",(int)c2);

printf(" \tend(NOW);%d \ n",(int)c1);

return 0;


}

解决方案



< Co********@gmail.com>在消息中写道

news:11 ********************** @ t31g2000cwb.googlegr oups.com ...

以下实验是TIME TRAVEL的演示。当我编写这个程序并进行测试时,我发现有时候
程序会自行参与时间旅行,但有时它会不会。




服用你的药物 - 更好的是服用三倍并服用它们。


其余的巨魔垃圾剪掉了。


Bill


>服用你的药物 - 更好的是服用三倍并服用它们。


所以因为你认为我需要药物治疗我错了吗?

如果你不够聪明,为什么还要打扰呢?
对我错的原因提出意见?


Co ******** @ gmail.com 写道:

以下实验是TIME TRAVEL的演示。在编写这个程序并进行测试时,我发现有时候
程序会在时间旅行中参与其中,但有时则不会。


我上周回答了这个问题,你没看过吗?

我会为你的利益重新发帖:

等待10
a = a +时间10
等待10
b = b +时间20
等待10
a = a +时间30 等待10
b = b +时间40
等待10
a = a +时间50
等待10
b = b +时间60
现在A = 90& B = 120
- 最后检查时间 -
C =时间60

使用逻辑我们可以推断出A应该恰好小于B的C / 2,


仅在时间时间在第一次等待之前正好是0。

但是当你运行程序时,时间差异在任何一个方向都会有很大差异。最重要的是,运行程序所需的时间也不是一成不变的。




NAME

clock - 确定处理器时间


描述

clock()函数返回程序使用的近似处理器时间




符合
ANSI C. POSIX要求CLOCKS_PER_SEC等于1000000

,与实际分辨率无关。


1)你的程序需要时间才能启动

2)你的程序需要时间来完成所有其他处理

除了调用时钟函数
3)操作系统可能需要不同的时间

来执行clock()函数

4)clock()的结果只是一个近似值

5)如果运行时间超过2148秒,那么整数溢出就会得到




谁''咚咚吗?


NB。 clock()不是ANSI C函数,如果你想进一步讨论它的

行为,那么在comp.unix.programmer等组中发帖


The following experiment is a demonstration of TIME TRAVEL. When
writing this program, and testing it out I found that sometimes the
program would engage itself in time travel but other times it would
not. After careful testing and reprogramming I have optimized the code
so it should work every time, however I recommend that you leave the
room while it is running and think of something else. It takes about 5
minuets to run so it is better if you don''t stare at a blank screen.

Here is how the double clock experiment operates:

The program loops like this:

LOOP

wait

a = a + time

wait

b = b + time

GOTO LOOP

c = time

Then it checks to see if the differance between a and b, is correct
compared to c. In normal physics it should be, but if the program time
travels then the output will be different. To show you what I mean
let me give you an example of the program in operation:

wait 10

a = a + time 10

wait 10

b = b + time 20

wait 10

a = a + time 30

wait 10

b = b + time 40

wait 10

a = a + time 50

wait 10

b = b+ time 60
-

Now A = 90 & B = 120

-imediately check time-

C = time 60

Using logic we can deduce that A should be exactly C / 2 smaller than
B, but when you run the program the time differance can vary
considerably in either direction. On top of that, the time it takes to
run the program is not constant either. What conclusions can we draw
from this?

I''ll show you some example output and then give you the source:

Time A: 146124514
Time B: 146270790
Time C: 293157

C / 2 = 146578.5
Actual Difference 145276

Time A was 1302.6 ticks into the future, or maybe time b was 1302.6
ticks into the past.

Here is some more real output:

Time A: 144371012
Time B: 144515341
Time C: 289188
C / 2 = 144594
real difference: 144329

time A was 265 ticks into the future, or time b was 265 ticks into the
past.

I wish I had an atomic clock to experiment with, but here is the
source:

#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <stdio.h>
#include <math.h>

int main()
{

clock_t c0, c1, c2; /* clock_t is defined on <time.h> and
<sys/types.h> as int */
long count;
printf ("using UNIX function clock to measure CPU time ... \n");

for (count = 0; count < 1000; count++){

for(int cnt1 =0; cnt1 < 100000; cnt1++){
c1 = clock();
}

c0 = c0 + clock();

for(int cnt2 =0; cnt2 < 100000; cnt2++){
c1 = clock();
}

c2 = c2 + clock();

}

c1 = clock();

printf ("\tend (CPU); %d\n", (int) c0);
printf ("\tend (CPU2); %d\n", (int) c2);
printf ("\tend (NOW); %d\n", (int) c1);
return 0;

}

解决方案


<Co********@gmail.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com...

The following experiment is a demonstration of TIME TRAVEL. When
writing this program, and testing it out I found that sometimes the
program would engage itself in time travel but other times it would
not.



Take your meds - better still triple the dose and take them.

Rest of troll junk snipped.

Bill


>Take your meds - better still triple the dose and take them.

So because you think I need medication that makes me wrong?
Why do you even bother posting if you aren''t intelligent enough to
offer an opinion about why I am wrong?


Co********@gmail.com wrote:

The following experiment is a demonstration of TIME TRAVEL. When
writing this program, and testing it out I found that sometimes the
program would engage itself in time travel but other times it would
not.
I answered this last week, didn''t you read it?
I''ll re-post for your benefit:
wait 10
a = a + time 10
wait 10
b = b + time 20
wait 10
a = a + time 30
wait 10
b = b + time 40
wait 10
a = a + time 50
wait 10
b = b+ time 60
Now A = 90 & B = 120
-imediately check time-
C = time 60

Using logic we can deduce that A should be exactly C / 2
smaller than B,
Only if "time" was exactly 0 before the first wait.
but when you run the program the time differance can vary
considerably in either direction. On top of that, the time it takes to
run the program is not constant either.



NAME
clock - Determine processor time

DESCRIPTION
The clock() function returns an approximation of processor time
used by the program.

CONFORMING TO
ANSI C. POSIX requires that CLOCKS_PER_SEC equals 1000000
independent of the actual resolution.

1) Your program takes time to start up
2) Your program takes time to do all of its other processing
besides calling the clock function
3) The operating system may take varying amounts of time
to execute the clock() function
4) The results of clock() are only an approximation
5) If you run this for more than 2148 seconds then you get
an integer overflow.

Who''d a thunk it?

NB. clock() is not an ANSI C function, if you want to debate its
behaviour further, then post in a group such as comp.unix.programmer


这篇关于双时钟实验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆