题目: 2次ping1 不等于 1次ping2
文/523066680
::
这里ping1指 ping -n 1 127.1>nul ; ping2 指ping -n 2 127.1>nul
偶然发现 for /l %%a in (1,1,2) do (ping -n 1 127.1>nul) 跟ping -n 2 127.1>nul
等待的时间相差甚远,所以,他们不相等。
我尝试了把for 中的 2 改为 9 依然不到一秒,感觉这个"精确度"还可以,所以后来写
特效一直用,我开始学批处理的时候是很乱来的,后来简化为
for /l %%a in (1,1,2) do (ping -n>nul)
终于,在群里发代码的时候有人问,怎么不直接 ping -n 2 127.1>nul (下面简称为ping2)
我回答ping2 的时间大于 两次 ping1 的时间,而 2 次 ping1 带来的效果刚刚好。
再后来HAT说,直接 "ping -n>nul" 是错误的句子,如果ping -n>nul达到的效果,那么其他
命令应该也一样,遂以attrib为例,一试,时间真的一样,于是晕晕的下线了。
唉,忘了反驳了,要是用echo 就得几百次了。attrib也是刚好有一点的延时.
以下整理个人观点:
后来看到一些批处理例如: 逐字读文章的批处理 还有一些特效等
为了达到适合的速度,有的用 几千次echo, 有的用 生成 sleep.xxx
我认为我所倡导的方法是比较好的,用代码说话吧:
@echo off
color 4e
set str= cn-dos 523066680 祝 大 家 新 年 快 乐 !
for /l %%a in (0,1,50) do (
call,set /p x=%%str:~%%a,1%%<nul
for /l %%b in (1,1,5) do (ping -n 1 127.0>nul)
)
exit
怎么样?这个打字的速度刚刚好吧?
对于这个打字效果,用 几千次 echo,>nul的缺点在于
执行次数多,对于不同的机子,拖延的时间可能会不一样。
ping -n 2 127.1>nul 打字拖延时间太长。
生成 sleep 的我没话说,只是个人不习惯....
for /l %%b in (1,1,N) do (ping -n 1 127.0>nul)
的好处就在于,1-9 次的时间都是不超过1秒的,可以通过选择 1-9 次 这来达到比较详细
的延时效果,相对于echo, 次数更好选择,而且对于不同的机子,一般效果一样。
(范围一般选 1-9 ,再大就接近秒了...)
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:
@echo off
color 4e
set str= cn-dos 523066680 祝 大 家 新 年 快 乐 !
for /l %%a in (0,1,50) do (
call,set /p x=%%str:~%%a,1%%<nul
for /l %%b in (1,1,5) do (ping -n 1 127.0>nul)
)
exit
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...)