“回声”在.bat是相当慢 [英] "echo" in .bat is quite slow

查看:214
本文介绍了“回声”在.bat是相当慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个小的.bat文件,希望能够创建一个矩阵(0和1)输出。

I wrote a little .bat file, hoping to be able to create a matrix-like (0 and 1) output.

问题是,非常慢,需要两秒才能填充一行。

The problem is, that it is pretty slow, it takes nearly two seconds to fill one line.

我能做些什么来让它运行更快

Is there something I can do to get it run faster?

Matrix.bat:

Matrix.bat:

@echo off
color 02

:start
if %random% LSS 16384 (
echo|set /p=1
) else (
echo|set /p=0
)
goto start


推荐答案

echo是很慢。所以构建你的线而不回应单个字符,然后立即回显整行。
另一个窍门: set / al =!random!& 1使用!random!(因此它给出 0 1 )。这比处理整数更快。

echo is very slow. So build your line without echoing the single chars, then echo the whole line at once. Another trick: set /a "l=!random! &1" uses the last Bit from !random! only (so it gives either 0or 1). This is quicker than processing Integer.

@echo off
setlocal ENABLEDELAYEDEXPANSION
:start
set line=
for /L %%i in (1,1,80) do (
    set /a "l=!random! &1"
    set line=!line!!l!
  ) 
  echo !line! 
)
goto start

这篇关于“回声”在.bat是相当慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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