Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local instance_new,queue = Instance.new
- local mutex = Instance.new("BindableEvent")
- coroutine.resume(coroutine.create(function()
- while true do
- mutex.Event:wait()
- coroutine.yield()
- for obj,parent in pairs(queue) do
- obj.Parent = parent
- end queue = nil
- end
- end))
- Instance = {
- new = function(class,parent)
- local obj = instance_new(class)
- if not parent then return obj end
- if queue then
- queue[obj] = parent
- else
- queue = {[obj]=parent}
- mutex:Fire()
- end return obj
- end;
- }
- -- localize, otherwise indexing might influence results
- local oldNew,newNew = instance_new,Instance.new
- -- easier to clean up
- local model = Instance.new("Folder",workspace)
- -- needed for a quick test at the bottom
- local wall
- local t = tick()
- for i=1,100 do
- wall = oldNew("Part")
- wall.Anchored = true
- wall.Size = Vector3.new(10,10,1)
- wall.CFrame = CFrame.new()
- wall.Parent = model
- end
- print(tick()-t)
- model:ClearAllChildren() wait(1) -- clean up
- local t = tick()
- for i=1,100 do
- wall = oldNew("Part",model)
- wall.Anchored = true
- wall.Size = Vector3.new(10,10,1)
- wall.CFrame = CFrame.new()
- end
- print(tick()-t)
- model:ClearAllChildren() wait(1) -- clean up
- local t = tick()
- for i=1,100 do
- wall = newNew("Part",model)
- wall.Anchored = true
- wall.Size = Vector3.new(10,10,1)
- wall.CFrame = CFrame.new()
- end
- print(tick()-t)
- local diff = tick()-t -- correction below
- print(wall.Parent)
- local t = tick()
- wall.Changed:wait()
- print(wall.Parent,tick()-t)
- wait() model:Destroy() -- clean up
- --[[ Output (ran several times)
- 0.00055575370788574
- 0.079145908355713
- 0.00058746337890625
- nil
- Folder 0.0012581348419189
- 0.0005803108215332
- 0.07579493522644
- 0.00054287910461426
- nil
- Folder 0.00094771385192871
- 0.00053167343139648
- 0.078535318374634
- 0.00054073333740234
- nil
- Folder 0.0022518634796143
- 0.00056672096252441
- 0.079301595687866
- 0.00054311752319336
- nil
- Folder 0.001467227935791
- 0.00053739547729492
- 0.075802326202393
- 0.00056886672973633
- nil
- Folder 0.0021722316741943
- --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement