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