{{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次运行,179毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,121毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,183毫秒
SpiderMonkey基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,251毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,201毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,290毫秒
JavaScriptCore基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,112毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,73毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,119毫秒
Nashorn基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,1277毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,524毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,635毫秒
ChakraCore基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,463毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,268毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,414毫秒
之后
V8基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,155毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :x]), 200000次运行,112毫秒
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c :x :y :z]), 200000次运行,169毫秒
SpiderMonkey基准测试
;;; select-keys
[m {:a 1, :b 2, :c 3, :d 4}], (select-keys m [:a :b :c]), 200000次运行,146毫秒
[[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毫秒