目前我正在做一些需要使用高效脚本的项目
部分脚本如下所示
- (setq _j
- (Boole 6
- (rem (/ _i 256) 256)
- (rem (/ (/ _i 256) 256) 256)
- (rem (/ (/ (/ _i 256) 256) 256) 256)
- )
- )
-
我正在尝试优化它,使用位操作方式
- (setq _j
- (Boole 6
- (lsh (lsh (lsh _i -8) 24) -24)
- (lsh (lsh (lsh _i -16) 16) -16)
- (lsh (lsh (lsh _i -24) 8) -8)
- )
- )
-
这似乎需要更多的时间来计算
完整的脚本是
- (defun c:tt3()
- (setq TIME0 (getvar "millisecs"))
- (repeat 3
- (setq _i 1)
- (setq nl '())
- (while (
- (setq _j
- (Boole 6
- (rem (/ _i 256) 256)
- (rem (/ (/ _i 256) 256) 256)
- (rem (/ (/ (/ _i 256) 256) 256) 256)
- )
- )
- (setq nl (cons _j nl))
- (setq _i (1+ _i))
- )
- )
- (princ "\nrem require")
- (print (/ (- (getvar "millisecs") TIME0 0.0) 1000.0))
- (setq TIME0 (getvar "millisecs"))
- (repeat 3
- (setq _i 1)
- (setq nl '())
- (while (
- (setq _j
- (Boole 6
- (lsh (lsh (lsh _i -8) 24) -24)
- (lsh (lsh (lsh _i -16) 16) -16)
- (lsh (lsh (lsh _i -24) 8) -8)
- )
- )
- (setq nl (cons _j nl))
- (setq _i (1+ _i))
- )
- )
- (princ "\nlsh require")
- (print (/ (- (getvar "millisecs") TIME0 0.0) 1000.0))
- (princ)
- )
-
并且输出是
rem要求
6.296
lsh要求
22.047
是任何人都可以优化它
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |