Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

What do you think is faster? Creating a part or cloning a part?

Asked by 4 years ago

I'm debating between the two and I'm not exactly sure which one would be faster not that the time difference is that heavy I just wanted to know for the sake of the question? Does anyone have any thoughts?

4 answers

Log in to vote
1
Answered by
IrishFix 124
4 years ago
Edited 4 years ago

I presume creating a part will be slower because it is required to set its parameters like name, size, position. But a clone just duplicates the part and its properties immidiately, therefore reducing the scripts lines and the possibility of lag on your game.

Hope i helped! - Irish

Ad
Log in to vote
3
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Clone takes about 0.00006 seconds Instance.new() takes about 0.00003 seconds

you can test by doing the following:

t1 = tick()
Instance.new("Part")
print(tick() - t1)

t1 = tick()
newPart:Clone()
print(tick()-t1)

Doesn't matter much if its only a part with no children. If the part/instance has children it'll take longer since it has to copy the children as well so keep that in mind.

Log in to vote
2
Answered by 4 years ago

I like where this discussion is going and I'd like to add on.

I've mainly studied ways to create a more efficient code in terms of helping the game run with ease. The topic of instance or clone has been one that occurred multiple times.

To start, I'd like to agree with @royaltoe as he is correct Instance is faster then :Clone(). Thought that is what you are asking for, I believe you would also like to know which one is more efficient.

Let's start with something simple such as a RemoteEvent. To instance it, it would be quick and there would only be 2 properties you would have to edit (the Name and Parent).

Next we have a part which has multitudes of properties, Color, Material, CFrame, and etc.

I think you know where I'm going with this. To use Instance and Clone efficiently, you should use understand what objects you are trying to perform the action on.

If it's something small such as a Bindable Event or Remote Event using Instance would indeed be faster and more efficient.

On the other hand, something with more properties such as parts and accessories and models is better to use :Clone().

In conclusion, to answer your question, @royaltoe would be correct. In terms of how to Clone and Instance is another topic. These are small things that may tweak your game performance in the very slightest, but not major unless placed inside a loop (this would cause tons of lag).

So Instance or Clone? That would depend on what you are instancing / cloning as well as what you plan to do after.

Hope this helped! Best of luck.

Log in to vote
0
Answered by 4 years ago

The usage of either one should heavily depend on what you want to do.

There is not such a large time difference between the two that would be noticeable or effect gameplay.

Answer this question