(time (make-instance 'Flat-Key :key "hello world" :fragment 1))产量:
Evaluation took:
0.005 seconds of real time
0.004367 seconds of total run time (0.004333 user, 0.000034 system)
80.00% CPU
22 lambdas converted
11,382,613 processor cycles
524,032 bytes consed
#<FLAT-KEY ((:KEY "hello world") (:HASH 1308457856027851121) (:BUCKET-INDEX 7)
(:HASH-AS-MASK "1228937CD01BF9-7-1")) {10045AB573}>这些金额正常吗?
如果没有,我如何改进我的代码?
如果正常,是什么原因造成的?
第二次和第三次对#'time的调用以±2.5m秒为单位,并且仍然占用±500 k字节(第二次调用删除了#'print-object方法)。
我在Emacs会话中使用SBCL。类定义有4个插槽。#'print-object做了一些工作;例如,它格式化了计算迟缓的散列)。但即使去除了#'print-object,它也需要2ms,并占用±500 k字节。
这个类及其函数是通过quicklisp的quickload加载的(我不确定quicklisp是否编译了代码;slime的slime-compile-file对速度或字节没有影响)。
Flat-Key是:
(defclass Flat-Key (Key)
()
(:documentation
"Keys without any level of nesting as used in conventional hash-tries and
Prokopecs CTrie."))Key是:
(defclass Key ()
((val :initarg :key
:reader get-key
:documentation
"The value of this Key")
(hash :initarg :hash
:initform nil
:documentation
"Cached `sxhash` of `key-val`, when nil it can be calculated.")
(hash-fragment-index :initarg :fragment
:reader get-fragment-index
:documentation
"The level in the trie for which `bucket-index` is valid.")
(bucket-index :initform nil
:documentation
"Cached index into the `CNode's` `Bitindexed-List`."))
(:documentation
"Common base of all keys in a Trie"))在Didier效率:实例化:关于Lisp的行为和性能,第2.1部分,国际Lisp会议,ILC,2009年3月,美国剑桥。2009年theILC会议记录。(可通过https://hal.archives-ouvertes.fr/hal-01543396/document获得),Didier在这个时间段内测量了数以百万计的“#”制造实例调用。
CLOS生成实例非常慢,导致SBCL中的堆耗尽。也是关于#'make-instance和数量的,但是看起来nrz正在做更先进的事情。我不认为我能在我的情况下采纳雷纳·若斯维希的建议。
tl;dr
具有4个槽类的#'make-instance占用2ms-5ms并占用400 k-500 k字节,这是正常的吗?
如果没有,我做错了什么?
如果正常的话,会发生什么?
发布于 2019-04-15 08:24:17
这是一个重新组合各种评论的社区答案。您可以对这个答案做出贡献,并添加关于基准测试的其他建议,而不一定是针对SBCL的。
make-instance需要调用finalize-inheritance,它可以有一个开销。您可能需要自己调用它,以便从后续调用中计算出此开销。(sb-ext:gc :full t)之前调用time,通常可以减少结果的差异,从而消除度量中的一个“噪声”源。time影响不大,但您永远不会知道。https://stackoverflow.com/questions/55679532
复制相似问题