I'm trying to keep things as optimized as possible, and I was wondering if BrickColor.Black() is faster than BrickColor.new("Black"). Do any of you know?
Which method is more optimized?
2 answers
Don't do either. Don't recompute something when you know the answer in advance.
local BLACK = BrickColor.new("Black")
Using BLACK will involve no work at all, in comparison to BrickColor.foo() which involves (1) looking up BrickColor in the global table, (2) looking up whatever method you're calling in the BrickColor table, and (3) calling that function.
Do less work. Two things which are basically the same don't make a difference. Stop obsessing over "optimizing" code in this way. The real gains are from better algorithms.
If you're testing for efficiency, try logging tick() before and after execution.
Here's an example of the kind of code you would write to test the BrickColor speeds:
a = tick()
c = BrickColor.Black()
a = tick() - a
b = tick()
d = BrickColor.new("Black")
b = tick() - b
print("A = " .. a)
print("B = " .. b)
This returns
A = 4.7683715820313e-006
B = 5.9604644775391e-006
So BrickColor.Black() is indeed faster than BrickColor.new("Black")
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Don't do either -- they return constants
Why the hell is this downvoted. The man wants to know the answer.