关键字函数可以加快。当在执行XHR时动态创建关键字时,这很重要。
现在的补丁现在更接近Clojure(使用子字符串)。它还对传递字符串进行了优化。
结果
`
(enable-console-print!)
(let [sims 1000000]
(dotimes [_ 2]
(doseq [x ["foo" "foo/bar" [nil "foo"] ["foo" "bar"] [:foo :bar] [nil :foo]]]
(prn "Testing keyword with: " x)
(if (vector? x)
(do (simple-benchmark [[a0 a1] x] (set! js/FOOO (keyword a0 a1)) sims)
(simple-benchmark [[a0 a1] x] (set! js/FOOO (keyword2 a0 a1)) sims))
(do (simple-benchmark [] (set! js/FOOO (keyword x)) sims)
(simple-benchmark [] (set! js/FOOO (keyword2 x)) sims))))))
"测试关键字: " "foo"
[], (set! js/FOOO (keyword x)), 1000000 次,194 毫秒
[], (set! js/FOOO (keyword2 x)), 1000000 次,71 毫秒
"测试关键字: " "foo/bar"
[], (set! js/FOOO (keyword x)), 1000000 次,260 毫秒
[], (set! js/FOOO (keyword2 x)), 1000000 次,104 毫秒
"测试关键字: " [nil "foo"] [[a0 a1] x], (set! js/FOOO (keyword a0 a1)), 1000000 次,278 毫秒
[[a0 a1] x], (set! js/FOOO (keyword2 a0 a1)), 1000000 次,188 毫秒
"测试关键字: " ["foo" "bar"] [[a0 a1] x], (set! js/FOOO (keyword a0 a1)), 1000000 次,379 毫秒
[[a0 a1] x], (set! js/FOOO (keyword2 a0 a1)), 1000000 次,215 毫秒
"测试关键字: " [:foo :bar] [[a0 a1] x], (set! js/FOOO (keyword a0 a1)), 1000000 次,351 毫秒
[[a0 a1] x], (set! js/FOOO (keyword2 a0 a1)), 1000000 次,207 毫秒
"测试关键字: " [nil :foo] [[a0 a1] x], (set! js/FOOO (keyword a0 a1)), 1000000 次,376 毫秒
[[a0 a1] x], (set! js/FOOO (keyword2 a0 a1)), 1000000 次,37 毫秒
`