Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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
declare函数是否会导致Clojure中出现任何性能问题?_Clojure_Clojurescript - Fatal编程技术网

declare函数是否会导致Clojure中出现任何性能问题?

declare函数是否会导致Clojure中出现任何性能问题?,clojure,clojurescript,Clojure,Clojurescript,如你所知,如果我们想使用一个函数而不在之前声明它,我们需要使用declare函数,所以我的问题是使用declare函数会导致性能问题吗 Clojure有单次编译,所以它必须在那里做一些折衷,我想?Clojure没有单次编译,只是编译单元不是一个文件。有关参考,请参阅。declare所做的只是定义一个在当前名称空间中没有值的var,以便以后可以重新定义它。因此,对正常VAR没有性能影响 但是,如果您开始考虑优化代码,您可能会开始添加一些东西,比如定义一些代码的内联版本,在declare调用和内联函

如你所知,如果我们想使用一个函数而不在之前声明它,我们需要使用
declare
函数,所以我的问题是使用
declare
函数会导致性能问题吗


Clojure有
单次编译
,所以它必须在那里做一些折衷,我想?

Clojure没有单次编译,只是编译单元不是一个文件。有关参考,请参阅。declare所做的只是定义一个在当前名称空间中没有值的var,以便以后可以重新定义它。因此,对正常VAR没有性能影响

但是,如果您开始考虑优化代码,您可能会开始添加一些东西,比如定义一些代码的内联版本,在declare调用和内联函数定义之间编译的任何东西都不会内联该调用

(declare some-func)
(defn other-func [] (some-func))
(defn some-func
  {:inline (fn [] "test-inline")}
  [] "test")
(other-func) ;;=> "test"
(defn other-func [] (some-func))
(other-func) ;;=> "test-inline"

Clojure没有单通道编译器,只是编译单元不是文件。有关参考,请参阅。declare所做的只是定义一个在当前名称空间中没有值的var,以便以后可以重新定义它。因此,对正常VAR没有性能影响

但是,如果您开始考虑优化代码,您可能会开始添加一些东西,比如定义一些代码的内联版本,在declare调用和内联函数定义之间编译的任何东西都不会内联该调用

(declare some-func)
(defn other-func [] (some-func))
(defn some-func
  {:inline (fn [] "test-inline")}
  [] "test")
(other-func) ;;=> "test"
(defn other-func [] (some-func))
(other-func) ;;=> "test-inline"

我尝试了以下标准:

(ns speed-test.core
  (:require [criterium.core :as crit]))

(declare this)
(defn bench-this [] (crit/bench (this)))
(defn this [])

(defn that [])
(defn bench-that [] (crit/bench (that)))

我找不到
这个
那个
之间的显著差异。因为在这两种情况下,平均执行时间都是7-8ns,所以我感觉我们正在测量HotSpot无法完全覆盖的虚无的幽灵

我尝试了如下准则:

(ns speed-test.core
  (:require [criterium.core :as crit]))

(declare this)
(defn bench-this [] (crit/bench (this)))
(defn this [])

(defn that [])
(defn bench-that [] (crit/bench (that)))

我找不到
这个
那个
之间的显著差异。因为在这两种情况下,平均执行时间都是7-8ns,所以我感觉我们正在测量HotSpot无法完全覆盖的虚无的幽灵

Clojure不完全具有单次编译:Clojure不完全具有单次编译: