评论由:michalmarczyk
首先,为了完整性,这里有一个新的补丁(0001-CLJ-1372-consistent-hasheq-for-java.util.-List-Map-M-alternative.patch),它不会对未另外处理的类型进行额外默念。在PHM单例中,它的速度更慢;具体细节见下文。同时,这里有GitHub上的分支
https://github.com/michalmarczyk/clojure/tree/alien-hasheq-3
至于新的结果,性能损失相当大,我害怕
`
;; with patch (murmur hashCode for default version)
user=> (let [class-instance java.lang.String character-instance \a var-instance #'hash] (c/bench (clojure.lang.Util/hasheq class-instance)) (c/bench (clojure.lang.Util/hasheq character-instance)) (c/bench (clojure.lang.Util/hasheq var-instance)))
WARNING: Final GC required 1.409118084170768 % of runtime
Evaluation count : 655363680 in 60 samples of 10922728 calls.
Execution time mean : 96.459888 ns
Execution time std-deviation : 1.019817 ns
Execution time lower quantile : 95.079086 ns ( 2.5%)
Execution time upper quantile : 98.684168 ns (97.5%)
Overhead used : 1.708347 ns
Evaluation count : 675919140 in 60 samples of 11265319 calls.
Execution time mean : 88.965959 ns
Execution time std-deviation : 0.825226 ns
Execution time lower quantile : 87.817159 ns ( 2.5%)
Execution time upper quantile : 90.755688 ns (97.5%)
Overhead used : 1.708347 ns
Evaluation count : 574987680 in 60 samples of 9583128 calls.
Execution time mean : 103.881498 ns
Execution time std-deviation : 1.103615 ns
Execution time lower quantile : 102.257474 ns ( 2.5%)
Execution time upper quantile : 106.071144 ns (97.5%)
Overhead used : 1.708347 ns
在60个样本中发现了1个异常值(1.6667%)
low-severe 1 (1.6667 %)
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers
nil
;;; 1.6.0
user=> (let [class-instance java.lang.String character-instance \a var-instance #'hash] (c/bench (clojure.lang.Util/hasheq class-instance)) (c/bench (clojure.lang.Util/hasheq character-instance)) (c/bench (clojure.lang.Util/hasheq var-instance)))
WARNING: Final GC required 1.3353133083866688 % of runtime
Evaluation count : 1829305260 in 60 samples of 30488421 calls.
Execution time mean : 34.205701 ns
Execution time std-deviation : 0.379106 ns
Execution time lower quantile : 33.680636 ns ( 2.5%)
Execution time upper quantile : 34.990138 ns (97.5%)
Overhead used : 1.718257 ns
在60个样本中发现2个异常值。
low-severe 1 (1.6667 %)
low-mild 1 (1.6667 %)
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers
Evaluation count : 1858100340 in 60 samples of 30968339 calls.
Execution time mean : 30.401309 ns
Execution time std-deviation : 0.213878 ns
Execution time lower quantile : 30.095976 ns ( 2.5%)
Execution time upper quantile : 30.871497 ns (97.5%)
Overhead used : 1.718257 ns
Evaluation count : 1592932200 in 60 samples of 26548870 calls.
Execution time mean : 36.292934 ns
Execution time std-deviation : 0.333512 ns
Execution time lower quantile : 35.795063 ns ( 2.5%)
Execution time upper quantile : 36.918183 ns (97.5%)
Overhead used : 1.718257 ns
在60个样本中发现了1个异常值(1.6667%)
low-severe 1 (1.6667 %)
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers
nil
`
使用新补丁(默认情况下没有额外默念步骤)的PHM和Class/Character/Var结果
`
user=> (let [phm (apply hash-map (interleave (range 128) (range 128))) juhm (java.util.HashMap. phm)] #_(assert (= (hash phm) (hash juhm))) (c/bench (unchecked-add (clojure.lang.Util/hasheq phm) (unchecked-add (clojure.lang.Util/hasheq "foo") (clojure.lang.Util/hasheq 123)))))
WARNING: Final GC required 1.258952964663877 % of runtime
Evaluation count : 1007768460 in 60 samples of 16796141 calls.
Execution time mean : 58.195608 ns
Execution time std-deviation : 0.482804 ns
Execution time lower quantile : 57.655857 ns ( 2.5%)
Execution time upper quantile : 59.154655 ns (97.5%)
Overhead used : 1.567532 ns
在60个样本中发现了1个异常值(1.6667%)
low-severe 1 (1.6667 %)
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers
nil
user=> (let [class-instance java.lang.String character-instance \a var-instance #'hash] (c/bench (clojure.lang.Util/hasheq class-instance)) (c/bench (clojure.lang.Util/hasheq character-instance)) (c/bench (clojure.lang.Util/hasheq var-instance)))
Evaluation count : 647944080 in 60 samples of 10799068 calls.
Execution time mean : 91.275863 ns
Execution time std-deviation : 0.659943 ns
Execution time lower quantile : 90.330980 ns ( 2.5%)
Execution time upper quantile : 92.711120 ns (97.5%)
Overhead used : 1.567532 ns
Evaluation count : 699506160 in 60 samples of 11658436 calls.
Execution time mean : 84.564131 ns
Execution time std-deviation : 0.517071 ns
Execution time lower quantile : 83.765607 ns ( 2.5%)
Execution time upper quantile : 85.569206 ns (97.5%)
Overhead used : 1.567532 ns
在60个样本中发现了1个异常值(1.6667%)
low-severe 1 (1.6667 %)
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers
评估次数:594919980,来源于9915333次调用中的60个样本。
Execution time mean : 100.336792 ns
Execution time std-deviation : 0.811312 ns
执行时间下四分位数:99.313490纳秒(2.5%)
执行时间上四分位数:102.167675纳秒(97.5%)
Overhead used : 1.567532 ns
在60个样本中发现了3个离群值(5.0000%)
low-severe 3 (5.0000 %)
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers
nil
`