javascript中按位运算符的性能 [英] Performance of bitwise operators in javascript

查看:189
本文介绍了javascript中按位运算符的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++ / java / C#等语言中使用按位运算符背后的主要思想之一是它们非常快。但我听说在javascript中它们非常慢(不可否认,几毫秒可能并不重要)。为什么会这样?

One of the main ideas behind using bitwise operators in languages like C++/java/C# is that they're extremely fast. But I've heard that in javascript they're very slow (admittedly a few milliseconds probably doesn't matter much today). Why is this so?

这个问题讨论了何时使用按位运算符,所以我将这个问题的重点改为性能。)

(this question discusses when bitwise operators are used, so I'm changing the focus of this question to performance.)

推荐答案

你想什么时候使用它们?当您想要按位操作时,您可能希望使用它们。就像你使用布尔运算符进行布尔运算一样,使用数学运算符进行数学运算。

When would you want to use them? You would want to use them when you want to do bitwise operations. Just like you'd use boolean operators to do boolean operations, and mathematical operators to do mathematical operations.

如果你对按位运算符感到满意,那么使用它们是很自然的对于某些应用程序除了过度优化的布尔数组之外,它们可以用于许多目的。当然,这些情况在Javascript编程中并不经常出现,但这并不是运营商不应该可用的原因。

If you are comfortable with bitwise operators it is very natural to use them for some applications. They can be used for many purposes other than an over-optimized boolean array. Of course, these circumstances don't come up very often in Javascript programming, but that's no reason why the operators shouldn't be available.

这篇关于javascript中按位运算符的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆