{{select-keys}}使用{{not=}}来比较关键字。相反,使用{{keyword-identical?}}可以得到很好的性能提升(在基准和引擎中获得平均1.34的提升)。请注意,使用{{identical?}}和{{lookup-sentinel}}似乎不会提高性能。
加速摘要
V8: 1.15, 1.08, 1.08
SpiderMonkey: 1.71, 1.48, 1.67
JavaScriptCore: 1.33, 1.35, 1.25
Nashorn: 1.16, 1.04, 0.97
ChakraCore: 1.59, 1.66, 1.72
之前
使用V8基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 179 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000 runs, 121 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000 runs, 183 msecs
使用SpiderMonkey基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 251 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000 runs, 201 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000 runs, 290 msecs
使用JavaScriptCore基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 112 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000 runs, 73 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000 runs, 119 msecs
使用Nashorn基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 1277 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000 runs, 524 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000 runs, 635 msecs
使用ChakraCore基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 463 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000 runs, 268 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000 runs, 414 msecs
之后
使用V8基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 155 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000 runs, 112 msecs
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000 runs, 169 msecs
使用SpiderMonkey基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000 runs, 146 msecs
[[m {:a 1, :b 2, :c 3, :d 4}]], (select-keys m [:a :b :x]), 200000次运行,135毫秒
[[m {:a 1, :b 2, :c 3, :d 4}]], (select-keys m [:a :b :c :x :y :z]), 200000次运行,173毫秒
使用JavaScriptCore基准测试
;;; select-keys
[[m {:a 1, :b 2, :c 3, :d 4}]], (select-keys m [:a :b :c]), 200000次运行,84毫秒
[[m {:a 1, :b 2, :c 3, :d 4}]], (select-keys m [:a :b :x]), 200000次运行,54毫秒
[[m {:a 1, :b 2, :c 3, :d 4}]], (select-keys m [:a :b :c :x :y :z]), 200000次运行,95毫秒
使用Nashorn基准测试
;;; select-keys
[[m {:a 1, :b 2, :c 3, :d 4}]], (select-keys m [:a :b :c]), 200000次运行,1099毫秒
[[m {:a 1, :b 2, :c 3, :d 4}]], (select-keys m [:a :b :x]), 200000次运行,502毫秒
[[m {:a 1, :b 2, :c 3, :d 4}]], (select-keys m [:a :b :c :x :y :z]), 200000次运行,648毫秒
使用ChakraCore基准测试
;;; select-keys
[[m {:a 1, :b 2, :c 3, :d 4}]], (select-keys m [:a :b :c]), 200000次运行,292毫秒
[[m {:a 1, :b 2, :c 3, :d 4}]], (select-keys m [:a :b :x]), 200000次运行,151毫秒
[[m {:a 1, :b 2, :c 3, :d 4}]], (select-keys m [:a :b :c :x :y :z]), 200000次运行,240毫秒