![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-04 18:30 |
48,038 topics / 350,123 posts / today 0 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » [Discussion] 2 times ping 1 is not equal to 1 time ping 2 |
| Printable Version 2,274 / 2 |
| Floor1 523066680 | Posted 2008-12-27 17:30 |
| 银牌会员 Posts 1,133 Credits 2,362 | |
|
Title: 2 pings of 1 are not equal to 1 ping of 2
Text / 523066680 :: Here ping1 refers to ping -n 1 127.1>nul; ping2 refers to ping -n 2 127.1>nul Accidentally discovered that for /l %%a in (1,1,2) do (ping -n 1 127.1>nul) is quite different in waiting time from ping -n 2 127.1>nul, so they are not equal. I tried changing the 2 in the for to 9 and it still didn't take more than a second. I felt this "precision" was still okay, so later I always used it when writing special effects. When I started learning batch processing, I was very random, and then simplified it to for /l %%a in (1,1,2) do (ping -n>nul) Finally, when I posted the code in the group, someone asked why not just ping -n 2 127.1>nul (hereinafter referred to as ping2) I replied that the time of ping2 is greater than the time of two ping1s, and the effect of two ping1s is just right. Later, HAT said that directly "ping -n>nul" is a wrong sentence. If the effect achieved by ping -n>nul is the case, then other commands should be the same. So taking attrib as an example, I tried it and the time was really the same, so I left the line dizzy. Alas, I forgot to refute. If you use echo, you have to do it hundreds of times. Attrib also has a little delay just right. The following sorts out personal views: Later I saw some batch processing examples: batch processing that reads articles character by character and some special effects, etc. In order to achieve a suitable speed, some use thousands of echos, and some use generating sleep.xxx I think the method I advocate is better. Let's use code: How about? Is the typing speed just right? For this typing effect, the disadvantage of thousands of echos,>nul is that the number of executions is large, and the delay time may be different for different computers. ping -n 2 127.1>nul has too long a typing delay time. I have nothing to say about generating sleep, it's just that I don't get used to it.... The advantage of for /l %%b in (1,1,N) do (ping -n 1 127.0>nul) is that the time for 1-9 times is all within 1 second. You can choose 1-9 times to achieve a more detailed delay effect. Compared with echo, the number of times is easier to choose, and the effect is generally the same for different computers. (Range is generally selected from 1-9, and if it is larger, it is close to seconds...) |
|
| Floor2 pooronce | Posted 2008-12-27 18:01 |
| 中级用户 Posts 250 Credits 484 | |
|
I don't know if anyone has calculated the miscellaneous time consumption of ping...
ping -n 1 -w 2850 99>nul |
|
| Floor3 BC | Posted 2008-12-28 13:59 |
| 中级用户 Posts 175 Credits 338 | |
|
Personally, I think it has something to do with the tree-planting principle
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |