Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance Mandelbrot集合函数未按预期执行_Performance_Clojure - Fatal编程技术网

Performance Mandelbrot集合函数未按预期执行

Performance Mandelbrot集合函数未按预期执行,performance,clojure,Performance,Clojure,这里有一个来自中国的例子 (导入'java.awt.image.buffereImage '(java.awt颜色渲染提示)) (defn-逃逸 [^双a0^双b0^长深度] (循环[a a0,b b0,迭代0] (续) (=迭代深度)-1 :其他(重现(+a0(-(*a a)(*b))) (+b0(适用于*[2 a b])) (包括迭代(()())) (定义mandelbrot[rmin rmax imin imax &{:关键点[宽度高度深度] :或{宽80高40深1000}] (让[man

这里有一个来自中国的例子

(导入'java.awt.image.buffereImage
'(java.awt颜色渲染提示))
(defn-逃逸
[^双a0^双b0^长深度]
(循环[a a0,b b0,迭代0]
(续)
(<4(+(*a)(*b))迭代
(>=迭代深度)-1
:其他(重现(+a0(-(*a a)(*b)))
(+b0(适用于*[2 a b]))
(包括迭代(()()))
(定义mandelbrot[rmin rmax imin imax
&{:关键点[宽度高度深度]
:或{宽80高40深1000}]
(让[mandelbrot]帮忙
(fn[^双rmin^双rmax
^双imin^双imax
]
(让[跨步宽度(/(-rmax rmin)宽度)
步幅-h(/(-imax-imin)高度)]
(循环[x 0
y(十二月高度)
逃逸[]]
(如果(=x宽度)
(如果(零?y)
(分区宽度转义)
(第0次复发(第y年12月)逃逸)
(重复(包括x)y(联合逃逸)
(逃生(+rmin(*x大步-w))
(+imin(*y-h))
深度(()()()())))]
(mandelbrot帮助rmin rmax imin imax)))
(定义渲染文本)
[mandelbrot网格]
(doseq[行曼德布罗特网格]
(doseq[国际热核实验堆逃生区]
(打印)(如果(负?逸出iter)
\*
\(空间)
(println)))
(defn)渲染图像
[mandelbrot网格]
(让[调色板]
(二)
[c(范围500)]
(Color/getHSBColor 0.0 0.0(/(Math/log c)(Math/log 500щщ))
高度(mandelbrot网格计数)
宽度(计数(第一个mandelbrot网格))
img(BuffereImage.宽度高度BuffereImage/TYPE_INT_RGB)
^java.awt.Graphics2D g(.getGraphics img)]
(doseq[[y行](地图索引向量mandelbrot栅格)
[x escape iter](映射索引向量行)]
(.setColor g(如果(负)逸出iter)
(调色板0)
(调色板(mod(dec(count调色板))(inc-escape iter()()))
(.drawRect g x y 1 1))
(.g)
(img)
(do(时间)(曼德尔布罗特-2.25 0.75-1.51.5
:宽度1600:高度1200:深度1000)
零)
除了在我的机器上运行60秒,根据书中的描述,只需要8秒(在其他例子中,我的笔记本电脑上的结果总是更好)


有什么我做错了吗?

你从哪里得到的代码?这绝对不是书中(基于我的PDF副本,第449-452页)或。尤其是
转义
中的
(apply*[2 a b])
是疯狂的;这永远不会很快(至少如果没有任何程度的[琐碎的]源代码级优化,Clojure不幸不适用)。更奇怪的是,这段特殊的片段没有出现在书中的任何地方,我也无法在我们曾经合作编写这本书的git repo的历史中找到它

也许你只是在摆弄这些例子?如果不是,我真的很想知道你的样品来自哪里,因为它绝对不能代表我们的意图或最佳实践(显然,考虑到你看到的时间安排)

无论如何,这里是/github示例repo中的“fast
escape
”函数:

(defn- escape
  [^double a0 ^double b0 depth]
  (loop [a a0
         b b0
         iteration 0]
    (cond
      (< 4 (+ (* a a) (* b b))) iteration
      (>= iteration depth) -1
      :else (recur (+ a0 (- (* a a) (* b b)))
              (+ b0 (* 2 (* a b)))
              (inc iteration)))))


user> (do (time (mandelbrot -2.25 0.75 -1.5 1.5
                  :width 1600 :height 1200 :depth 1000))
          nil)
"Elapsed time: 1987.460104 msecs"
(defn-escape
[^双a0^双b0深度]
(循环[a a0
b b0
迭代0]
(续)
(<4(+(*a)(*b))迭代
(>=迭代深度)-1
:其他(重现(+a0(-(*a a)(*b)))
(+b0(*2(*a b)))
(包括迭代(()()))
用户>(do(时间)(mandelbrot-2.25 0.75-1.51.5
:宽度1600:高度1200:深度1000)
零)
“运行时间:1987.460104毫秒”

深度
参数暗示为
^long
(我应该在书中的示例中包含这一点)会在我的笔记本电脑上下降到1450ms。

你从哪里获得该代码的?这绝对不是书中(基于我的PDF副本,第449-452页)或。尤其是
转义
中的
(apply*[2 a b])
是疯狂的;这永远不会很快(至少如果没有任何程度的[琐碎的]源代码级优化,Clojure不幸不适用)。更奇怪的是,这段特殊的片段没有出现在书中的任何地方,我也无法在我们曾经合作编写这本书的git repo的历史中找到它

也许你只是在摆弄这些例子?如果不是,我真的很想知道你的样品来自哪里,因为它绝对不能代表我们的意图或最佳实践(显然,考虑到你看到的时间安排)

无论如何,这里是/github示例repo中的“fast
escape
”函数:

(defn- escape
  [^double a0 ^double b0 depth]
  (loop [a a0
         b b0
         iteration 0]
    (cond
      (< 4 (+ (* a a) (* b b))) iteration
      (>= iteration depth) -1
      :else (recur (+ a0 (- (* a a) (* b b)))
              (+ b0 (* 2 (* a b)))
              (inc iteration)))))


user> (do (time (mandelbrot -2.25 0.75 -1.5 1.5
                  :width 1600 :height 1200 :depth 1000))
          nil)
"Elapsed time: 1987.460104 msecs"
(defn-escape
[^双a0^双b0深度]
(循环[a a0
b b0
迭代0]
(续)
(<4(+(*a)(*b))迭代
(>=迭代深度)-1
:其他(重现(+a0(-(*a a)(*b)))
(+b0(*2(*a b)))
(包括迭代(()()))
用户>(do(时间)(mandelbrot-2.25 0.75-1.51.5
:宽度1600:高度1200:深度1000)
零)
“运行时间:1987.460104毫秒”

深度
参数暗示为
^long
(我应该在书中的示例中包含这一点)会在我的笔记本电脑上下降到1450ms。

其他示例是否使用java.awt?可能是系统特定的图形。另外,也许一些评测会让我们了解一些事情:在我的i7上,它运行了大约一分半钟。也许查斯有一个真正的机器野兽?书中是否有其他类似的时间报告与您的结果不匹配?不完全是,这是第一个。其他示例是否使用java.awt?C