简体   繁体   English

单引号比双引号更快?

[英]Single quotes faster than double quotes?

I was wondering which quotes I should use for strings in JavaScript. 我想知道应该在JavaScript中对字符串使用哪些引号。 I tend to use single quotes, but use double quotes depending on the scenario ("I'm pregnant!"). 我倾向于使用单引号,但根据情况使用双引号(“我怀孕了!”)。 I ran a JavaScript performance test, and it appears single quotes are faster? 我进行了JavaScript性能测试,看来单引号更快了吗?

Performance Test Link 性能测试链接

Does anyone know why single quotes would be faster??? 有谁知道为什么单引号会更快???

证明证明2

Let's take the numbers in your screenshot as an example. 让我们以屏幕快照中的数字为例。

  • single quotes: 711,222,327 ops/sec, ±0.27%. 单引号:711,222,327个操作/秒,±0.27%。
  • double quotes: 708,941,116 ops/sec, ±0.31%. 双引号:708,941,116个操作/秒,±0.31%。

They differ from their average by 0.1%, which is less than they vary between runs . 它们与平均值之间的差异为0.1%, 小于两次运行之间的差异 The results placing one over another aren't meaningful. 一个接一个的结果没有意义。 As to why they vary between runs: empty loops are fast and can be influenced a lot by your CPU changing clock speeds to adjust to temperature, or background processes, or butterflies from the other side of the world. 至于为什么它们在运行之间会有所不同:空循环速度很快,并且CPU更改时钟速度以适应温度,后台进程或来自世界另一端的蝶形,这可能会大大影响空循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM