Efficiency of color selection in html. RGB vs hex vs name

后端 未结 3 1958
轻奢々
轻奢々 2021-02-04 04:04

Is there a difference in the speed a browser can parse a colour?

for example, the colour red, i could use the following css:

.red
{
    color:red;
    co         


        
3条回答
  •  面向向阳花
    2021-02-04 04:35

    red is the easiest to parse, but will require a lookup in to table to get the actual value to be used.

    #ff0000 is the next easiest to parse, requires 3 Text -> Int conversions to get the actual value.

    rgb(255,0,0) is the most difficult to parse, and still requires the 3 Text -> Int conversions to get the actual value.

    The second is likely the fastest overall since the red method (likely) requires a hashing operation (another Text -> Int conversion, just not what we normally think about), and then the lookup. Also the red token can be arbitrarily long compared to #ff0000.

    I won't comment on the micro-optimization aspect or its wisdom.

提交回复
热议问题