明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: baitang36

[讨论] 大家一起来玩优化,用最短的时间画一个bmp图片

[复制链接]
 楼主| 发表于 2022-6-15 08:31:54 | 显示全部楼层
本帖最后由 baitang36 于 2022-6-15 08:36 编辑

;改成一张大表,节省了读文件时间,总的反而慢了
;改成这样后是8.386秒,改前是10.3秒

(defun c:tt (/ pt r x lst x1 x2 r g b c lc strc )
(setq f (open "c:/00/tt.txt" "R"))
(setq f1 (open "c:/00/tt6.txt" "w"))
(setq list1 nil)
(while (setq s (read-line f))
  (setq k (read s))
     (setq
            r (caddr k)
            g (cadddr k)
            b (car (cddddr k))
            c (lm:rgb->true r g b)
      )

(setq list1 (cons c list1 ))
)
(setq list1 (reverse list1))
(setq strc (vl-prin1-to-string list1))
(write-line strc f1)
(close f1)
(close f)

(setq f (open "c:/00/tt6.txt" "R"))
(setq t0 (getvar "TDUSRTIMER"))
(setq s (read-line f))
(setq lc (read s))
(setq x 0 y 0)
(while  (< x 512 ) ;宽512像素   ;while比repeat快0.1秒
  (while (< y 654) ;高654像素
  (setq c (car lc))
    (entmake
      (list
        (cons 0 "LWPOLYLINE")
        (cons 100 "AcDbEntity")
        (cons 100 "AcDbPolyline")
        (cons 8 "Image2PL")
        (cons 90 2)
        (cons 43 1.0)
        (cons 420 c)
        (cons 10 (list x y))
        (cons 10 (list (+ 1 x) y))
      )
    )
    (setq y (+ 1 y))
  )
  (setq y 0)
  (setq x (+ 1 x))
)
(close f)
(princ "\n程序共用时" )
(princ  (*  (-  (getvar "TDUSRTIMER" )  t0 )  86400 )  )
(princ "秒" )
(princ)
)

(defun LM:RGB->True ( r g b )
  (+
    (lsh r 16)
    (lsh g  8)
    b
  )
)
;(vlisp-compile 'st "c:/00/tt.lsp")

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2022-6-15 08:53:11 | 显示全部楼层
本帖最后由 baitang36 于 2022-6-15 09:34 编辑


;用上一个保留函数 syz-read-list
;改成这样后是7.784秒,改前是10.3秒

(defun c:tt (/ pt r x lst x1 x2 r g b c lc strc )
(setq f (open "c:/00/tt.txt" "R"))
(setq f1 (open "c:/00/tt6.txt" "w"))
(setq list1 nil)
(while (setq s (read-line f))
  (setq k (read s))
     (setq
            r (caddr k)
            g (cadddr k)
            b (car (cddddr k))
            c (lm:rgb->true r g b)
      )

(setq list1 (cons c list1 ))
)
(setq list1 (reverse list1))
(setq strc (vl-prin1-to-string list1))
(write-line strc f1)
(close f1)
(close f)

(setq f (open "c:/00/tt6.txt" "R"))
(setq t0 (getvar "TDUSRTIMER"))
(load "c:/00/syz-read-list.fas")
(setq lc (syz-read-list f))
(setq x 0 y 0)
(while  (< x 512 ) ;宽512像素   ;while比repeat快0.1秒
  (while (< y 654) ;高654像素
  (setq c (car lc))
  (setq lc(cdr lc))
    (entmake
      (list
        (cons 0 "LWPOLYLINE")
        (cons 100 "AcDbEntity")
        (cons 100 "AcDbPolyline")
        (cons 8 "Image2PL")
        (cons 90 2)
        (cons 43 1.0)
        (cons 420 c)
        (cons 10 (list x y))
        (cons 10 (list (+ 1 x) y))
      )
    )
    (setq y (+ 1 y))
  )
  (setq y 0)
  (setq x (+ 1 x))
)
(close f)
(princ "\n程序共用时" )
(princ  (*  (-  (getvar "TDUSRTIMER" )  t0 )  86400 )  )
(princ "秒" )
(princ)
)

(defun LM:RGB->True ( r g b )
  (+
    (lsh r 16)
    (lsh g  8)
    b
  )
)
;(vlisp-compile 'st "c:/00/tt.lsp")

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
回复 支持 1 反对 0

使用道具 举报

发表于 2022-6-15 09:19:25 | 显示全部楼层
测起来效率太低了,跑一次1分钟,省去caddddr那里,我这里测这两个都比你的慢
你的代码测起来,52-53秒多


;;;程序共用时57.522秒

(defun c:tt1 (/ pt r x lst x1 x2)
  (setq f (open "E:\\Users\\2858\\Desktop\\tt.txt" "R"))
  (setq t0 (getvar "TDUSRTIMER"))
  (while (setq s (read-line f))
    (setq k (read s))
    (apply 'emake k)
  )
  (close f)
  (princ "\n程序共用时")
  (princ (* (- (getvar "TDUSRTIMER") t0) 86400))
  (princ "秒")
  (princ)
)
;;;程序共用时56.548秒
(defun c:tt2 (/ pt r x lst x1 x2)
  (setq f (open "E:\\Users\\2858\\Desktop\\tt.txt" "R"))
  (setq t0 (getvar "TDUSRTIMER"))
  (while (setq s (read-line f))
    (setq k (read s))
    (eval (cons 'emake k))
  )
  (close f)
  (princ "\n程序共用时")
  (princ (* (- (getvar "TDUSRTIMER") t0) 86400))
  (princ "秒")
  (princ)
)
(defun emake (x y r g b l)
  (setq c (lm:rgb->true r g b))
  (entmake
    (list
      (cons 0 "LWPOLYLINE")
      (cons 100 "AcDbEntity")
      (cons 100 "AcDbPolyline")
      (cons 8 "Image2PL")
      (cons 90 2)
      (cons 43 1.0)
      (cons 420 c)
      (cons 10 (list x y))
      (cons 10 (list (1+ x) y))
    )
  )
)
(defun LM:RGB->True ( r g b )
  (+
    (lsh (fix r) 16)
    (lsh (fix g)  8)
    (fix b)
  )
)


发表于 2022-6-15 10:15:03 | 显示全部楼层
本帖最后由 vectra 于 2022-6-15 10:21 编辑

读文件循环3s 加上判断6~7s 包含赋值14s 包含entmake(完整代码)25-40s
按耗时子句排序
entmake 11~26s,赋值7~8s ,判断3~4s ,读文件循环3s
各段优化空间均不大,对于33万次循环,已是比较理想的结果。

i5 4590 RAM:20G CAD2021




PS:直接以光栅图像插入得了
 楼主| 发表于 2022-6-15 10:58:18 | 显示全部楼层
vectra 发表于 2022-6-15 10:15
读文件循环3s 加上判断6~7s 包含赋值14s 包含entmake(完整代码)25-40s
按耗时子句排序
entmake 11~26s, ...

很详细的实验。看来entmake是最大的问题
 楼主| 发表于 2022-6-15 12:30:54 | 显示全部楼层
;改成画line后是3.586秒,改前是10.3秒

(defun c:tt (/ pt r x lst x1 x2 r g b c lc strc )
(setq f (open "c:/00/tt.txt" "R"))
(setq f1 (open "c:/00/tt6.txt" "w"))
(setq list1 nil)
(while (setq s (read-line f))
  (setq k (read s))
     (setq
            r (caddr k)
            g (cadddr k)
            b (car (cddddr k))
            c (lm:rgb->true r g b)
      )

(setq list1 (cons c list1 ))
)
(setq list1 (reverse list1))
(setq strc (vl-prin1-to-string list1))
(write-line strc f1)
(close f1)
(close f)

(setq f (open "c:/00/tt6.txt" "R"))
(setq t0 (getvar "TDUSRTIMER"))
(load "c:/00/syz-read-list.fas")
(setq lc (syz-read-list f))
(setq x 0 y 0)
(while  (< x 512 ) ;宽512像素   ;while比repeat快0.1秒
  (while (< y 654) ;高654像素
  (setq c (car lc))
  (setq lc(cdr lc))
    (entmake
      (list
        (cons 0 "LINE")
        (cons 420 c)
        (cons 10 (list x y))
        (cons 11 (list (+ 1 x) y))
      )
    )
    (setq y (+ 1 y))
  )
  (setq y 0)
  (setq x (+ 1 x))
)
(close f)
(princ "\n程序共用时" )
(princ  (*  (-  (getvar "TDUSRTIMER" )  t0 )  86400 )  )
(princ "秒" )
(princ)
)

(defun LM:RGB->True ( r g b )
  (+
    (lsh r 16)
    (lsh g  8)
    b
  )
)
;(vlisp-compile 'st "c:/00/tt.lsp")
发表于 2022-6-15 22:25:31 来自手机 | 显示全部楼层
大佬666  牛批
 楼主| 发表于 2022-6-16 08:31:23 | 显示全部楼层
;改成画point后是3.436秒,改前是10.3秒

(defun c:tt (/ pt r x lst x1 x2 r g b c lc strc )
(setq f (open "c:/00/tt.txt" "R"))
(setq f1 (open "c:/00/tt6.txt" "w"))
(setq list1 nil)
(while (setq s (read-line f))
  (setq k (read s))
     (setq
            r (caddr k)
            g (cadddr k)
            b (car (cddddr k))
            c (lm:rgb->true r g b)
      )

(setq list1 (cons c list1 ))
)
(setq list1 (reverse list1))
(setq strc (vl-prin1-to-string list1))
(write-line strc f1)
(close f1)
(close f)

(setq f (open "c:/00/tt6.txt" "R"))
(setq t0 (getvar "TDUSRTIMER"))
(load "c:/00/syz-read-list.fas")
(setq lc (syz-read-list f))
(setq x 0 y 0)
(while  (< x 512 ) ;宽512像素   ;while比repeat快0.1秒
  (while (< y 654) ;高654像素
  (setq c (car lc))
  (setq lc(cdr lc))
    (entmake
      (list
        (cons 0 "point")
        (cons 420 c)
        (cons 10 (list x y))
       ; (cons 11 (list (+ 1 x) y))
      )
    )
    (setq y (+ 1 y))
  )
  (setq y 0)
  (setq x (+ 1 x))
)
(close f)
(princ "\n程序共用时" )
(princ  (*  (-  (getvar "TDUSRTIMER" )  t0 )  86400 )  )
(princ "秒" )
(princ)
)

(defun LM:RGB->True ( r g b )
  (+
    (lsh r 16)
    (lsh g  8)
    b
  )
)
;(vlisp-compile 'st "c:/00/tt.lsp")
发表于 2022-6-16 09:06:00 | 显示全部楼层
楼主雄才!
期待楼主做一个在DCL窗口中预览dwg的插件
 楼主| 发表于 2022-6-16 09:18:58 | 显示全部楼层
本帖最后由 baitang36 于 2022-6-16 09:20 编辑

;再引入两个保留函数entlist->lresb和ads-entmake
;用时是3.222秒,改前是10.3秒

(defun c:tt (/ pt r x lst x1 x2 r g b c lc strc )
(setq f (open "c:/00/tt.txt" "R"))
(setq f1 (open "c:/00/tt6.txt" "w"))
(setq list1 nil)
(while (setq s (read-line f))
  (setq k (read s))
     (setq
            r (caddr k)
            g (cadddr k)
            b (car (cddddr k))
            c (lm:rgb->true r g b)
      )

(setq list1 (cons c list1 ))
)
(setq list1 (reverse list1))
(setq strc (vl-prin1-to-string list1))
(write-line strc f1)
(close f1)
(close f)

(setq f (open "c:/00/tt6.txt" "R"))
(setq t0 (getvar "TDUSRTIMER"))
(load "c:/00/syz-read-list.fas")
(load "c:/00/syz-ads-entmake.fas")
(load "c:/00/syz-entlist-lresb.fas")
(setq lc (syz-read-list f))
(setq x 0 y 0)
(while  (< x 512 ) ;宽512像素   ;while比repeat快0.1秒
  (while (< y 654) ;高654像素
  (setq c (car lc))
  (setq lc(cdr lc))
    (syz-ads-entmake
     (syz-entlist->lresb (list
        (cons 0 "point")
        (cons 420 c)
        (cons 10 (list x y))
       ; (cons 11 (list (+ 1 x) y))
      ))
    )
    (setq y (+ 1 y))
  )
  (setq y 0)
  (setq x (+ 1 x))
)
(close f)
(princ "\n程序共用时" )
(princ  (*  (-  (getvar "TDUSRTIMER" )  t0 )  86400 )  )
(princ "秒" )
(princ)
)

(defun LM:RGB->True ( r g b )
  (+
    (lsh r 16)
    (lsh g  8)
    b
  )
)
;(vlisp-compile 'st "c:/00/tt.lsp")

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-9-29 17:29 , Processed in 0.174549 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表