找回密码
 加入
搜索
查看: 4561|回复: 8

[AU3基础] 时间间隔统计函数好像有点问题~~[已解决]

  [复制链接]
发表于 2012-11-22 02:16:23 | 显示全部楼层 |阅读模式
本帖最后由 annybaby 于 2012-11-22 15:47 编辑

标记为[已解决]吧,因为讨论的意义不是很大~~
AU本身的问题,太短的时间计算不了,实践得出的经验au的最短延时约为10毫秒
即sleep(1)~sleep(10)几乎无差别,都相当于sleep(10)





Local $t2
For $m=1 To 100
$t = TimerInit()
$arr = _findcolor(0,0,154,112, 0xF000FF)
$t2 &= TimerDiff($t)&@LF
Sleep(1000)
Next
ConsoleWrite($t2)


代码中的_findcolor()是用来搜索屏幕像素的自定义函数,本来是打算测试一下代码效率的,但测试几次后发现,有时返回的用时会是负数,于是就测试了一百次,看看返回的负值有多少个~~

其中,sleep(1000)是多余的,只是为了结果更保险些~~

得到的结果出现负值的概率还挺大的!!~~


140.24995710594
56.4743440893039
66.240585674963
76.1914190828566
57.5678994542191
57.3125487492303
-12.2697520565465
53.6694999552639
146.430615832382
65.6906533054741
71.8202070493624
135.258298553181
143.238442550907
150.947186623369
74.3685862854797
127.496207428304
63.3407214622927
54.009087751246
64.8533265264233
147.012936111535
-4.79260695883749
-9.36612000863144
135.212153492313
67.6011131403188
6.91249401325242
-6.27595090603833
130.638494655348
-4.12246859260117
66.9312795061131
73.0168365762646
-15.8480834513139
-13.0167581564502
-17.097744772451
95.9299426851155
-22.1038057293832
101.82371962548
-11.5321915969748
-19.3663121108614
71.4762124808556
75.5055351757604
141.168974700399
55.5257011731394
-12.0111982442382
55.1016457634879
136.86799734741
142.074626190113
65.0441850918143
54.7941616711315
67.434723662258
152.619036541528
140.932037915191
56.3454208617759
147.485694436404
139.607338831492
-9.06408793545365
-15.2590064367405
69.3611179823477
2.43561049036068
54.1891749077646
139.173066741051
53.777131940022
138.390229627953
131.996096377426
62.2685478650337
65.9495192181176
-16.8272806218849
141.81779392957
64.8710867723141
66.5009526165376
53.4612069283117
145.56883049215
53.733970516255
147.885496544791
148.767507881454
140.985353915464
-9.83356473318842
125.991371715183
65.5287148097662
52.7553591259085
147.07921611764
128.527932190544
137.680810302995
-21.673956726999
143.787427040626
-18.1220828092188
64.7279653479156
137.700677884033
73.5192544328247
143.268566285795
141.977121413872
127.178475076709
66.098331078983
53.353880728199
53.2318505497282
61.9456498055294
60.7462745325074
133.403577838245
53.5895517439198
60.8564396351637
63.9405540965143
发表于 2012-11-22 02:50:09 | 显示全部楼层
这么说有什么意义,_findcolor是什么样的?
 楼主| 发表于 2012-11-22 03:00:58 | 显示全部楼层
回复 2# netegg

原来帖子有说的,不过很明显,跟这个关系不大~~

比如说,下面的代码也一样

Local $t2
For $i=1 To 100
        $t1=TimerInit()
        Sleep(10)
        $t2&=TimerDiff($t1)&@LF
Next
ConsoleWrite($t2)


输出

93.279629795319
10.7062409540902
10.6596037957295
10.7384904448877
10.7003431524765
10.7577496144798
10.7084982868692
10.6801361031142
11.2043436156271
92.7773819360747
10.7137345199813
10.7629769003647
-71.3173402525223
92.6970742567223
10.7074819871265
-72.0874812502961
93.5322679115593
-71.8357441724604
11.532072125177
97.371242559328
10.6199691583817
11.0157534354721
10.4068993647469
10.7223891201718
-72.1202807324095
93.543160371152
10.6713320315995
10.7380788724389
10.7010757724878
10.7105529912686
10.7312184544455
10.7201849444482
10.62727956927
10.7046925574859
10.8202859954843
10.6102393120109
10.6830797408462
10.7198128450603
-71.9861723235949
10.6134297879507
10.7358068030505
95.3942800903144
10.8029089014384
-72.1520544412457
93.5401109456166
10.8215128182187
10.5879059804319
10.7310742461961
11.0073883043952
14.4653273895675
-72.2612469276801
93.646450845513
10.6381872917796
10.7162586906523
-72.1199970526781
11.4204454666505
98.2093745888223
-72.6582290805935
123.92983321316
11.8619553375473
15.0578227712194
-72.8207449356063
93.515015552386
16.4769993105372
9.88006663052689
-72.1565743698784
93.5867365252128
11.4523723309632
9.90565833171055
-72.087839139382
93.6080851354979
10.6546617684984
10.748681862918
11.6808160923775
11.5637837297306
9.85359546954522
-72.1253569680479
11.5540533570523
-73.0049436061536
10.7843355104919
10.7817029204802
93.4085140760935
10.7095024815398
-72.0955374388825
10.6564517402357
93.7502586801261
-72.0884686031273
10.5506423582786
93.499348957648
11.9821750182892
11.8715120287574
10.2400314731873
-72.0846439266748
94.521873338842
10.7329657952769
10.6443992989584
11.1613574522508
10.2672199912633
10.5934979974
-72.101644710873
 楼主| 发表于 2012-11-22 11:45:31 | 显示全部楼层
回复 3# annybaby

怪了,今天早上运行了相同的代码,结果相当稳定


11.6529633430699
15.9102765716692
15.2350785505645
15.4420015262756
16.4947217178495
14.7069113970685
15.5942912028631
15.6803773584906
16.2719733691219
16.0575948001368
15.1229204494619
15.4811720744191
15.2023236230626
15.2653803847267
15.2366585089866
15.4443883055709
16.4068687666114
14.6881703113076
16.2104665666693
15.0699192126523
15.7205273545433
15.2962358885293
16.1627536117471
16.0841683113602
14.6168390305518
15.6178900555249
15.7034593826478
14.6203052551249
15.917106918239
15.6511476013789
15.3493392279151
15.8579226862451
15.7312844398832
14.9553617010079
15.3763795689587
15.4391116023263
15.5184668824505
15.3450282887292
15.7379626851925
14.5223641483119
15.51379647904
15.4685155653799
15.6869708691877
15.6059766848241
15.6629962369411
15.173631746533
16.307810320781
14.6521591537065
15.9048682929397
15.9632346517197
15.360712086524
15.6264803557801
15.5733243862004
15.7734606984027
15.8092823873056
15.5501349964475
15.766985605642
15.4522817820584
16.604057787953
14.0791721270493
15.7460129996579
15.6520144206731
15.5109465540381
15.0824288834504
15.5490818662667
15.6365106181416
16.0154632772822
15.0805657745849
15.7061619431068
15.5392889660798
15.4981789952896
15.9583600431568
14.9692202836767
16.0210283939896
15.1035783268861
15.6864219362648
15.4434009631325
15.637029025552
15.4633809636589
15.5202152574932
15.4763711481277
15.6328959764217
15.6077750585511
15.1069077129549
15.624621983632
15.0407584010947
15.9545054077524
15.3729807110339
16.5303581484698
14.595881687324
16.3650414462777
15.2089776584827
15.2156595879056
15.8082039946317
15.7762248361885
14.6023430962343
15.8773516486408
15.3372900713139
15.8653282808347
15.5649414489092
发表于 2012-11-22 12:39:29 | 显示全部楼层
如果想准确些,试试用
#Include <WinAPIEx.au3>
_WinAPI_ZwDelayExecution
看看

评分

参与人数 1金钱 +10 收起 理由
annybaby + 10 感谢指导!!~

查看全部评分

 楼主| 发表于 2012-11-22 13:20:15 | 显示全部楼层
回复 5# netegg


    厉害,微秒级!
试了下,结果
延时时间稍长就比较准,如果太小的话,也不准~~估计是au3的timer**函数的问题
测试最短的是4000微秒(4毫秒)左右,都返回正数,3000微秒,就会有负数返回

下面测试1毫秒
#include <Array.au3>
#include <WinAPIEx.au3>

Dim $results[1]

_ArrayAdd($results, "_WinAPI_ZwDelayExecution()")

For $i = 0 To 50
 $t =TimerInit()
 _WinAPI_ZwDelayExecution(1000) ; 延时一毫秒!
 _ArrayAdd($results, TimerDiff($t))
Next
_ArrayDisplay($results)



结果
[1]|_WinAPI_ZwDelayExecution()
[2]|5.85444172521776
[3]|-2.72757243230441
[4]|6.54127417699534
[5]|1.90770137627957
[6]|-2.69525328280835
[7]|6.58306097207968
[8]|-2.74190784453041
[9]|1.99703007815584
[10]|6.8236846398779
[11]|-3.08954764348307
[12]|6.90182837293755
[13]|2.37752585458277
[14]|-2.66758243204126
[15]|-2.83276650614458
[16]|1.88496723770427
[17]|6.58600352622299
[18]|1.86922080997868
[19]|-2.70998026367727
[20]|7.24846030367622
[21]|1.35823478329518
[22]|1.80045156706402
[23]|1.8507002447304
[24]|1.92388147680324
[25]|-2.73796952711771
[26]|6.53386647719797
[27]|1.85730270256046
[28]|2.51845319860004
[29]|1.25982263624641
[30]|6.28840556827452
[31]|1.86208310307623
[32]|1.9339070024473
[33]|1.87995368542933
[34]|1.85630536038525
[35]|1.90047419804742
[36]|2.29030972869135
[37]|1.64354622246783
[38]|-2.80948922396779
[39]|1.95318860029999
[40]|1.83315860108945
[41]|1.90023157285335
[42]|1.95365648272414
[43]|1.73831372858609
[44]|2.06026315096971
[45]|2.98963027288756
[46]|1.41235809583958
[47]|6.29819267914002
[48]|1.8530391305492
[49]|1.91776163785164
[50]|1.84207362964133
[51]|-2.74812241783111
[52]|6.58362043104129
发表于 2012-11-22 13:45:09 | 显示全部楼层
timerdiff本身就不太准,如果非要算时间间隔的话,用pdh可能更好些
发表于 2012-11-22 14:30:02 | 显示全部楼层
。。我现在使用的就是timerdiff。运行了一天了。就是用来计时的,好像也挺准。
发表于 2012-11-22 15:25:54 | 显示全部楼层
回复 8# chenronting
时间长的话,误差可以忽略
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-18 10:25 , Processed in 0.076445 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表