{{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 runs, 135 msecs
数据[m{:a 1, :b 2, :c 3, :d 4}],使用),200000次运行,173毫秒
使用JavaScriptCore进行基准测试
;;; select-keys
数据[m{:a 1, :b 2, :c 3, :d 4}],使用),200000次运行,84毫秒
数据[m{:a 1, :b 2, :c 3, :d 4}],使用),200000次运行,54毫秒
数据[m{:a 1, :b 2, :c 3, :d 4}],使用),200000次运行,95毫秒
使用Nashorn进行基准测试
;;; select-keys
数据[m{:a 1, :b 2, :c 3, :d 4}],使用),200000次运行,1099毫秒
数据[m{:a 1, :b 2, :c 3, :d 4}],使用),200000次运行,502毫秒
数据[m{:a 1, :b 2, :c 3, :d 4}],使用),200000次运行,648毫秒
使用ChakraCore进行基准测试
;;; select-keys
数据[m{:a 1, :b 2, :c 3, :d 4}],使用),200000次运行,292毫秒
数据[m{:a 1, :b 2, :c 3, :d 4}],使用),200000次运行,151毫秒
数据[m{:a 1, :b 2, :c 3, :d 4}],使用),200000次运行,240毫秒