Last active
December 17, 2015 07:41
-
-
Save mezum/0ff696d046da133663fa to your computer and use it in GitHub Desktop.
cocos2d-x (3.8) を用いて steady_clock の精度を調査した時に用いたコード及びその結果
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AppDelegate::AppDelegate() | |
{ | |
std::thread th{[]{ | |
using clock = std::chrono::steady_clock; | |
constexpr int64_t LOOP_COUNT = 100000; | |
constexpr int64_t DIST_FREQ = 200; | |
constexpr int64_t DIST_SIZE = 16; | |
std::this_thread::sleep_for(std::chrono::seconds{10}); | |
int64_t min = std::numeric_limits<int64_t>::max(); | |
int64_t total = 0; | |
int64_t max = std::numeric_limits<int64_t>::min(); | |
float total2 = 0; | |
std::array<int, DIST_SIZE> dist{0}; | |
int overCount = 0; | |
for (int i = 0; i < LOOP_COUNT; i++) { | |
auto a = clock::now(); | |
auto b = clock::now(); | |
auto diff = std::chrono::duration_cast<std::chrono::nanoseconds>(b - a).count(); | |
if (diff < DIST_FREQ * DIST_SIZE) { | |
dist[diff / DIST_FREQ]++; | |
} | |
else { | |
overCount++; | |
} | |
total += diff; | |
total2 += diff * diff; | |
if (diff < min) min = diff; | |
if (diff > max) max = diff; | |
} | |
float mean = (float)total / LOOP_COUNT; | |
float sd = std::sqrt(total2 / LOOP_COUNT - mean * mean); | |
CCLOG("min:%lldns, max:%lldns, mean:%f.2ns, sd:%f.2ns", min, max, mean, sd); | |
for (int i = 0; i < DIST_SIZE; i++) { | |
CCLOG("%5lld - %5lld : %d", DIST_FREQ * i, DIST_FREQ * (i + 1) - 1, dist[i]); | |
} | |
CCLOG(" %5lld+: %d", DIST_FREQ * DIST_SIZE, overCount); | |
}}; | |
th.detach(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 出現値の関係で DIST_FREQ = 3000 に設定 | |
min:0ns, max:7294369ns, mean:1606.592041.2ns, sd:44291.617188.2ns | |
0 - 2999 : 96193 | |
3000 - 5999 : 0 | |
6000 - 8999 : 0 | |
9000 - 11999 : 0 | |
12000 - 14999 : 0 | |
15000 - 17999 : 0 | |
18000 - 20999 : 0 | |
21000 - 23999 : 0 | |
24000 - 26999 : 0 | |
27000 - 29999 : 0 | |
30000 - 32999 : 3784 | |
33000 - 35999 : 0 | |
36000 - 38999 : 0 | |
39000 - 41999 : 0 | |
42000 - 44999 : 0 | |
45000 - 47999 : 0 | |
48000+: 23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 出現値の関係で DIST_FREQ = 3000 に設定 | |
min:0ns, max:3417969ns, mean:973.510742.2ns, sd:21201.652344.2ns | |
0 - 2999 : 97488 | |
3000 - 5999 : 0 | |
6000 - 8999 : 0 | |
9000 - 11999 : 0 | |
12000 - 14999 : 0 | |
15000 - 17999 : 0 | |
18000 - 20999 : 0 | |
21000 - 23999 : 0 | |
24000 - 26999 : 0 | |
27000 - 29999 : 0 | |
30000 - 32999 : 2481 | |
33000 - 35999 : 0 | |
36000 - 38999 : 0 | |
39000 - 41999 : 0 | |
42000 - 44999 : 0 | |
45000 - 47999 : 0 | |
48000+: 31 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 出現値の関係で DIST_FREQ = 3000 に設定 | |
min:0ns, max:11597742ns, mean:2880.207275.2ns, sd:63398.468750.2ns | |
0 - 2999 : 92378 | |
3000 - 5999 : 0 | |
6000 - 8999 : 0 | |
9000 - 11999 : 0 | |
12000 - 14999 : 0 | |
15000 - 17999 : 0 | |
18000 - 20999 : 0 | |
21000 - 23999 : 0 | |
24000 - 26999 : 0 | |
27000 - 29999 : 0 | |
30000 - 32999 : 7586 | |
33000 - 35999 : 0 | |
36000 - 38999 : 0 | |
39000 - 41999 : 0 | |
42000 - 44999 : 0 | |
45000 - 47999 : 0 | |
48000+: 36 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 出現値の関係で DIST_FREQ = 20 に設定 | |
min:125ns, max:89875ns, mean:131.350372.2ns, sd:405.521515.2ns | |
0 - 19 : 0 | |
20 - 39 : 0 | |
40 - 59 : 0 | |
60 - 79 : 0 | |
80 - 99 : 0 | |
100 - 119 : 0 | |
120 - 139 : 92625 | |
140 - 159 : 0 | |
160 - 179 : 7334 | |
180 - 199 : 0 | |
200 - 219 : 10 | |
220 - 239 : 0 | |
240 - 259 : 1 | |
260 - 279 : 0 | |
280 - 299 : 1 | |
300 - 319 : 0 | |
320+: 29 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
min:416ns, max:531167ns, mean:530.464050.2ns, sd:2514.324951.2ns | |
0 - 199 : 0 | |
200 - 399 : 0 | |
400 - 599 : 98642 | |
600 - 799 : 9 | |
800 - 999 : 786 | |
1000 - 1199 : 512 | |
1200 - 1399 : 1 | |
1400 - 1599 : 4 | |
1600 - 1799 : 1 | |
1800 - 1999 : 0 | |
2000 - 2199 : 1 | |
2200 - 2399 : 2 | |
2400 - 2599 : 0 | |
2600 - 2799 : 0 | |
2800 - 2999 : 1 | |
3000 - 3199 : 0 | |
3200+: 41 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
min:1916ns, max:21347875ns, mean:5236.863770.2ns, sd:177577.484375.2ns | |
0 - 199 : 0 | |
200 - 399 : 0 | |
400 - 599 : 0 | |
600 - 799 : 0 | |
800 - 999 : 0 | |
1000 - 1199 : 0 | |
1200 - 1399 : 0 | |
1400 - 1599 : 0 | |
1600 - 1799 : 0 | |
1800 - 1999 : 49840 | |
2000 - 2199 : 18621 | |
2200 - 2399 : 31256 | |
2400 - 2599 : 20 | |
2600 - 2799 : 1 | |
2800 - 2999 : 5 | |
3000 - 3199 : 6 | |
3200+: 251 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
min:1666ns, max:2033417ns, mean:1856.185547.2ns, sd:12585.189453.2ns | |
0 - 199 : 0 | |
200 - 399 : 0 | |
400 - 599 : 0 | |
600 - 799 : 0 | |
800 - 999 : 0 | |
1000 - 1199 : 0 | |
1200 - 1399 : 0 | |
1400 - 1599 : 0 | |
1600 - 1799 : 95452 | |
1800 - 1999 : 1640 | |
2000 - 2199 : 1725 | |
2200 - 2399 : 972 | |
2400 - 2599 : 89 | |
2600 - 2799 : 8 | |
2800 - 2999 : 2 | |
3000 - 3199 : 1 | |
3200+: 111 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
min:740ns, max:5045037ns, mean:1054.027100.2ns, sd:33417.429688.2ns | |
0 - 199 : 0 | |
200 - 399 : 0 | |
400 - 599 : 0 | |
600 - 799 : 67411 | |
800 - 999 : 32180 | |
1000 - 1199 : 95 | |
1200 - 1399 : 23 | |
1400 - 1599 : 28 | |
1600 - 1799 : 45 | |
1800 - 1999 : 13 | |
2000 - 2199 : 11 | |
2200 - 2399 : 15 | |
2400 - 2599 : 9 | |
2600 - 2799 : 13 | |
2800 - 2999 : 31 | |
3000 - 3199 : 5 | |
3200+: 121 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 出現値の関係で DIST_FREQ = 3000 に設定 | |
min:0ns, max:8209980ns, mean:1082.862671.2ns, sd:36522.488281.2ns | |
0 - 2999 : 97574 | |
3000 - 5999 : 0 | |
6000 - 8999 : 0 | |
9000 - 11999 : 0 | |
12000 - 14999 : 0 | |
15000 - 17999 : 0 | |
18000 - 20999 : 0 | |
21000 - 23999 : 0 | |
24000 - 26999 : 0 | |
27000 - 29999 : 0 | |
30000 - 32999 : 2387 | |
33000 - 35999 : 0 | |
36000 - 38999 : 0 | |
39000 - 41999 : 0 | |
42000 - 44999 : 0 | |
45000 - 47999 : 0 | |
48000+: 39 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 出現値の関係で DIST_FREQ = 3000 に設定 | |
min:0ns, max:793457ns, mean:961.914062.2ns, sd:6403.461426.2ns | |
0 - 2999 : 96957 | |
3000 - 5999 : 0 | |
6000 - 8999 : 0 | |
9000 - 11999 : 0 | |
12000 - 14999 : 0 | |
15000 - 17999 : 0 | |
18000 - 20999 : 0 | |
21000 - 23999 : 0 | |
24000 - 26999 : 0 | |
27000 - 29999 : 0 | |
30000 - 32999 : 3022 | |
33000 - 35999 : 0 | |
36000 - 38999 : 0 | |
39000 - 41999 : 0 | |
42000 - 44999 : 0 | |
45000 - 47999 : 0 | |
48000+: 21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
min:364ns, max:1083177ns, mean:519.057007.2ns, sd:5515.062988.2ns | |
0 - 199 : 0 | |
200 - 399 : 438 | |
400 - 599 : 91801 | |
600 - 799 : 7024 | |
800 - 999 : 622 | |
1000 - 1199 : 41 | |
1200 - 1399 : 2 | |
1400 - 1599 : 0 | |
1600 - 1799 : 1 | |
1800 - 1999 : 1 | |
2000 - 2199 : 0 | |
2200 - 2399 : 1 | |
2400 - 2599 : 0 | |
2600 - 2799 : 0 | |
2800 - 2999 : 0 | |
3000 - 3199 : 0 | |
3200+: 69 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment