中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 搜索 | 上传 | 帮助 »
作者:
标题: 据说是p处理最快循环的代码 上一主题 | 下一主题
electronixtar
铂金会员





积分 7493
发帖 2672
注册 2005-9-2
状态 离线
『楼 主』:  据说是p处理最快循环的代码

原帖地址: groups.google.com/group/alt.ms ...
Okay, here is my final bisection thing, but it's now written in only ONE Line. That line is very long, exact 418 visible char long: (if not defined Result ... goto%0 Two things are required: ".BAT" extension, and a variable named Result must be empty. The testing loop, in (2147483647, -33554428, 0), would count down from 2147483647, and stop on 255. If a loop with that same speed for each number you see, it would have calc/found that number after more than four years. In other words: if you run the test loop (take about 4 seconds), and then see a message: 255. "All Done", Press any key ..., then you have displayed the same data as would have taken more than 260 years, So, I would say this loop is fast. Besides that, it shouldn't be a problem for you to rewrite it for whatever, other purpose than exit-codes/errorlevels... Benny @echo off setlocal enabledelayedexpansion (set Result=) for /L %%I in (2147483647, -33554428, 0) do ( call :ErrMake %%I call :ErrFind > nul echo !ErrFind!. REM if "!ErrFind!" neq "%%I" echo OOPS.& exit /b ) endlocal call:_& echo All Done.& pause goto:eof :ErrFind (if "!Result!"=="" set Result=%0&set Result=!Result:~1!&(if not errorlevel 1 set !Result!=0&set Result=&goto:eof)&set H=2147483647&(if errorlevel !H! set !Result!=!H!&set Result=&goto:eof)&set L=0)&set/a A=H/2+L/2&echo H:!H! A:!A! L:!L!&(if errorlevel !A! ((if !L!==!A! set/a A+=1&(if not errorlevel !A! set A=!L!)&set !Result!=!A!&set Result=&goto:eof)&set L=!A!)else set H=!A!)&goto%0 :ErrMake X [norm/both/user] if /i "%~2"=="norm" (set errorlevel=) if /i "%~2"=="both" (set errorlevel=%~1) if /i "%~2"=="user" ( cd.\&(set errorlevel=& if errorlevel 1 exit /b %~1 call:_ echo It is recognizable that a variable errorlevel echo have been manipulated, value is %errorlevel%. echo. echo "%~nx0" is ready to create the exit-code %~1, echo Please make a choice, 1...3: echo. echo 1: As requested, create an ERRORLEVEL %~1 echo. echo 2: Also set the synthetic errorlevel variable echo. echo 3: Normalize/restore the synthetic errorlevel echo so it is following the real DOS ERRORLEVEL echo.& (set /p errorlevel=?: ) if "!errorlevel!"=="3" set errorlevel=&exit /b %~1 if "!errorlevel!"=="2" (set errorlevel=%~1) else ( set errorlevel=%errorlevel%)) ) exit /b %~1 :_ for %%_ in (________________) do (echo %%_%%_%%_%%_%%_)
[ Last edited by electronixtar on 2007-2-23 at 01:46 AM ]




C:\>BLOG initiative.yo2.cn/ C:\>hh.exe ntcmds.chm::/ntcmds.htm C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
2007-2-20 05:59
查看资料  发送邮件  发短消息  网志   编辑帖子  回复  引用回复
qjbm
初级用户





积分 125
发帖 44
注册 2007-1-24
状态 离线
『第 2 楼』:  

@echo %dbg% off&setlocal enabledelayedexpansion

for /L %%I in (2147483647, -33554428, 0) do (
                                             call :errMake %%I
                                             call :errFind >NUL
                                             echo !errFind!.
                                             if  "!errFind!" neq "%%I" echo OOPS.& exit /b
                                             )
echo All Done.&pause
goto:eof


:errMake
exit /b %~1


:ErrFind
(
 if not defined Result set Result=%0&set Result=!Result:~1!&(
                                                             if not errorlevel 1 set !Result!=0&set Result=&goto:eof
                                                             )&set H=2147483647&(
                                                                                 if errorlevel !H! set !Result!=!H!&set H=&set Result=&goto:eof
                                                                                 )&set L=0
)&set/a A=H/2+L/2&echo H:!H! A:!A! L:!L!&(
                                          if errorlevel !A! (
                                                             (
                                                              if !L!==!A! set H=&set/a A+=1&(
                                                                                             if not errorlevel !A! set A=!L!
                                                                                             )&set L=&set !Result!=!A!&set A=&set Result=&goto:eof
                                                              )&set L=!A!
                                                             )else set H=!A!
                                          )&goto %0
此段代码不是一般的值得学习研究, 有别于本论坛中其他所有代码的,这是代码处理问题方式的一个另类. 看上去好象只是65次循环,其实它的计算次数几乎是爆炸模式递增的, 太不可思议了.我现在在想,本段代码是否是利用了batch的某个特性?? 这让我想起了下面这段代码.
type %~dpnx0>>%~dpnx0&%0
啊!我好象有点明白了.......它的计算次数不是几何递增模式的... 我再考虑考虑....... ------------------------------- FT!就是65次!!我被骗了! ---------------------------------
ECHO %DBG% OFF

FOR /L %%I IN (2147483647,-33554428,0) DO ECHO %%I
. [ Last edited by qjbm on 2007-2-19 at 11:48 PM ]


2007-2-20 11:39
查看资料  发送邮件  发短消息  网志   编辑帖子  回复  引用回复
electronixtar
铂金会员





积分 7493
发帖 2672
注册 2005-9-2
状态 离线
『第 3 楼』:  

恩,虽然只有65次,但是代码还是值得研究的。这年头的p处理都比较BT




C:\>BLOG initiative.yo2.cn/ C:\>hh.exe ntcmds.chm::/ntcmds.htm C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
2007-2-20 22:50
查看资料  发送邮件  发短消息  网志   编辑帖子  回复  引用回复
qjbm
初级用户





积分 125
发帖 44
注册 2007-1-24
状态 离线
『第 4 楼』:  

:ErrFind 段IF嵌套的比较BT.虽看不出有何实际意义,但其嵌套手法值得学习. ---------- 闲聊一下: 近来的论坛这是怎么了?? 满坛尽是灌水帖! 一些朋友发起的问题也让人打不起精神,甚至感觉烦躁...重复..重复..再重复.. 一天来4.5次,盼望出现个值得讨论的话题也找不到.... 我来的时候willsort 就走了,现在3742668 也辞职了. "无奈何" 也见收不见尾.qzwqzw也不知道干什么去了.........


2007-2-21 01:30
查看资料  发送邮件  发短消息  网志   编辑帖子  回复  引用回复
electronixtar
铂金会员





积分 7493
发帖 2672
注册 2005-9-2
状态 离线
『第 5 楼』:  

近来的论坛这是怎么了?? 满坛尽是灌水帖! 一些朋友发起的问题也让人打不起精神,甚至感觉烦躁...重复..重复..再重复.. 一天来4.5次,盼望出现个值得讨论的话题也找不到.... 我来的时候willsort 就走了,现在3742668 也辞职了. "无奈何" 也见收不见尾.qzwqzw也不知道干什么去了.........
过节不说这些,呵呵,春节快乐啊。SB终究是SB,不必烦心理会。




C:\>BLOG initiative.yo2.cn/ C:\>hh.exe ntcmds.chm::/ntcmds.htm C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
2007-2-21 04:33
查看资料  发送邮件  发短消息  网志   编辑帖子  回复  引用回复
namejm
荣誉版主

batch fan


积分 5226
发帖 1737
注册 2006-3-10
来自 成都
状态 离线
『第 6 楼』:  

  我不删帖子已经好几天。




尺有所短,寸有所长,学好CMD没商量。 考虑问题复杂化,解决问题简洁化。
2007-2-21 04:41
查看资料  发短消息  网志   编辑帖子  回复  引用回复
electronixtar
铂金会员





积分 7493
发帖 2672
注册 2005-9-2
状态 离线
『第 7 楼』:  

呵呵,论坛发展到一定程度了,大量的FAQ是不可避免的。




C:\>BLOG initiative.yo2.cn/ C:\>hh.exe ntcmds.chm::/ntcmds.htm C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
2007-2-21 05:23
查看资料  发送邮件  发短消息  网志   编辑帖子  回复  引用回复
gne3
高级用户

DOS学徒


积分 526
发帖 252
注册 2007-2-12
状态 离线
『第 8 楼』:  

受了,研究。。。。。。。


2007-2-21 08:35
查看资料  发短消息  网志   编辑帖子  回复  引用回复
tuminghao
初级用户




积分 128
发帖 9
注册 2005-6-22
状态 离线
『第 9 楼』:  

我不顶帖子已经好多年……


2007-4-26 14:57
查看资料  发送邮件  发短消息  网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: