local k=require(script.Parent.Pooler)local J=Instance.new("\080\097\114\116")local function i(k,J,i)local c={}while true do local k=os.clock()J()table.insert(c,os.clock()-k)if#c==i then break end task.wait()end local O=0 for k,J in pairs(c)do O+=J end O=O/#c print(k,"\058 ",O)end local c=1000 print("\082\117\110\110\105\110\103 \098\101\110\099\104\109\097\114\107\115 \120"..c)print()print("\069\113\117\105\118\097\108\101\110\116 \116\111\058")print("\108\111\099\097\108 \105\110\115\116\097\110\099\101 \061 \073\110\115\116\097\110\099\101\046\110\101\119\040\'\080\097\114\116\'\041")print("\105\110\115\116\097\110\099\101\046\067\070\114\097\109\101 \061 \119\111\114\107\115\112\097\099\101\046\069\109\105\116\116\101\114\046\067\070\114\097\109\101")print("\105\110\115\116\097\110\099\101\046\080\097\114\101\110\116 \061 \119\111\114\107\115\112\097\099\101\046\080\097\114\116\115")print("\103\097\109\101\046\068\101\098\114\105\115\058\065\100\100\073\116\101\109\040\105\110\115\116\097\110\099\101\044 \051\041")print()print("\065\108\108 \080\111\111\108\101\114\115 \117\115\101 \050\053\048 \112\097\114\116\115\046")print("-------------------------------------------------------------------------------")do i("\066\097\115\101\108\105\110\101",function()local k=Instance.new("\080\097\114\116")k.CFrame=workspace.Emitter.CFrame k.Parent=workspace.Parts game.Debris:AddItem(k,3)end,c)for k,J in pairs(workspace.Parts:GetChildren())do game.Debris:AddItem(J,0)end local O=k.new(J,{count=250})i("\080\111\111\108\101\114 \040\105\110 \110\105\108\080\097\114\101\110\116 \109\111\100\101\041",function()local k=O:Get()k.CFrame=workspace.Emitter.CFrame k.Parent=workspace.Parts task.delay(3,function()O:Return(k)end)end,c)task.wait(3)O:Destroy()local h=k.new(J,{count=250,returnMethod="\099\102\114\097\109\101"})i("\080\111\111\108\101\114 \040\105\110 \099\102\114\097\109\101 \109\111\100\101\041",function()local k=h:Get()k.CFrame=workspace.Emitter.CFrame k.Parent=workspace.Parts task.delay(3,function()h:Return(k)end)end,c)task.wait(3)h:Destroy()local z=k.new(J,{count=250,unsafe=true})i("\080\111\111\108\101\114 \040\105\110 \110\105\108\080\097\114\101\110\116 \109\111\100\101\041 \040\117\110\115\097\102\101\041",function()local k=z:Get()k.CFrame=workspace.Emitter.CFrame k.Parent=workspace.Parts task.delay(3,function()z:Return(k)end)end,c)task.wait(3)z:Destroy()local t=k.new(J,{count=250,returnMethod="\099\102\114\097\109\101",unsafe=true})i("\080\111\111\108\101\114 \040\105\110 \099\102\114\097\109\101 \109\111\100\101\041 \040\117\110\115\097\102\101\041",function()local k=t:Get()k.CFrame=workspace.Emitter.CFrame k.Parent=workspace.Parts task.delay(3,function()t:Return(k)end)end,c)task.wait(3)t:Destroy()end print("-------------------------------------------------------------------------------")print()print("\069\113\117\105\118\097\108\101\110\116 \116\111\058")print("\073\110\115\116\097\110\099\101\046\110\101\119\040\'\080\097\114\116\'\041\058\068\101\115\116\114\111\121\040\041")print()print("\065\108\108 \080\111\111\108\101\114\115 \117\115\101 \050\053\048 \112\097\114\116\115\046")print("-------------------------------------------------------------------------------")do i("\066\097\115\101\108\105\110\101",function()(Instance.new("\080\097\114\116")):Destroy()end,c)local O=k.new(J,{count=250})i("\080\111\111\108\101\114 \040\105\110 \110\105\108\080\097\114\101\110\116 \109\111\100\101\041",function()O:Return(O:Get())end,c)O:Destroy()local h=k.new(J,{count=250,unsafe=true})i("\080\111\111\108\101\114 \040\105\110 \110\105\108\080\097\114\101\110\116 \109\111\100\101\041 \040\117\110\115\097\102\101\041",function()h:Return(h:Get())end,c)h:Destroy()end print("-------------------------------------------------------------------------------")print()print("\066\101\110\099\104\109\097\114\107\115 \099\111\109\112\108\101\116\101")
-- this script acts as a benchmark and a more intensive test of Pooler, and is also where the 42% increase in performance was gathered.
-- the 42% comes from the first benchmark, comparing the baseline to unsafe CFrame mode.

local Pooler = require(script.Parent.Pooler)

local template = Instance.new("Part")

local function benchmark(name, action, count)
	local times = {}

	while true do
		local start = os.clock()

		action()

		table.insert(times, os.clock() - start)

		if #times == count then
			break
		end

		task.wait()
	end

	local avg = 0
	for _, v in pairs(times) do
		avg += v
	end

	avg = avg / #times

	print(name, ": ", avg)
end

local benchmarkCount = 1000

print("Running benchmarks x" .. benchmarkCount)
print()
print("Equivalent to:")
print("local instance = Instance.new('Part')")
print("instance.CFrame = workspace.Emitter.CFrame")
print("instance.Parent = workspace.Parts")
print("game.Debris:AddItem(instance, 3)")
print()
print("All Poolers use 250 parts.")
print("-------------------------------------------------------------------------------")

do
	benchmark("Baseline", function()
		local instance = Instance.new("Part")

		instance.CFrame = workspace.Emitter.CFrame
		instance.Parent = workspace.Parts

		game.Debris:AddItem(instance, 3)
	end, benchmarkCount)

	for _, v in pairs(workspace.Parts:GetChildren()) do
		game.Debris:AddItem(v, 0)
	end

	local poolNil = Pooler.new(template, { count = 250 })

	benchmark("Pooler (in nilParent mode)", function()
		local instance = poolNil:Get()

		instance.CFrame = workspace.Emitter.CFrame
		instance.Parent = workspace.Parts

		task.delay(3, function()
			poolNil:Return(instance)
		end)
	end, benchmarkCount)

	task.wait(3)

	poolNil:Destroy()

	local poolCframe = Pooler.new(template, { count = 250, returnMethod = "cframe" })

	benchmark("Pooler (in cframe mode)", function()
		local instance = poolCframe:Get()

		instance.CFrame = workspace.Emitter.CFrame
		instance.Parent = workspace.Parts

		task.delay(3, function()
			poolCframe:Return(instance)
		end)
	end, benchmarkCount)

	task.wait(3)

	poolCframe:Destroy()

	local poolNilUnsafe = Pooler.new(template, { count = 250, unsafe = true })

	benchmark("Pooler (in nilParent mode) (unsafe)", function()
		local instance = poolNilUnsafe:Get()

		instance.CFrame = workspace.Emitter.CFrame
		instance.Parent = workspace.Parts

		task.delay(3, function()
			poolNilUnsafe:Return(instance)
		end)
	end, benchmarkCount)

	task.wait(3)

	poolNilUnsafe:Destroy()

	local poolCframeUnsafe = Pooler.new(template, { count = 250, returnMethod = "cframe", unsafe = true })

	benchmark("Pooler (in cframe mode) (unsafe)", function()
		local instance = poolCframeUnsafe:Get()

		instance.CFrame = workspace.Emitter.CFrame
		instance.Parent = workspace.Parts

		task.delay(3, function()
			poolCframeUnsafe:Return(instance)
		end)
	end, benchmarkCount)

	task.wait(3)

	poolCframeUnsafe:Destroy()
end

print("-------------------------------------------------------------------------------")

print()
print("Equivalent to:")
print("Instance.new('Part'):Destroy()")
print()
print("All Poolers use 250 parts.")
print("-------------------------------------------------------------------------------")

do
	benchmark("Baseline", function()
		Instance.new("Part"):Destroy()
	end, benchmarkCount)

	local poolNil = Pooler.new(template, { count = 250 })

	benchmark("Pooler (in nilParent mode)", function()
		poolNil:Return(poolNil:Get())
	end, benchmarkCount)

	poolNil:Destroy()

	local poolNilUnsafe = Pooler.new(template, { count = 250, unsafe = true })

	benchmark("Pooler (in nilParent mode) (unsafe)", function()
		poolNilUnsafe:Return(poolNilUnsafe:Get())
	end, benchmarkCount)

	poolNilUnsafe:Destroy()
end

print("-------------------------------------------------------------------------------")
print()
print("Benchmarks complete")
