Optimize my optimizer

I am trying to see how fast my code runs, but this operation that takes the 60FPS average is slowing down the actual reading, which is ridiculous for what it does.

function engine:draw(t,RPM)
        local b4=tick() -- store before ran
	--code we are checking the run time of:
 	Piston:Update(t)
	Piston2:Update(t)
	Piston3:Update(t)
	Piston4:Update(t)
        --sending out the average to print:
	table.insert(avg,1,tick()-b4 )
	local sum = 0
	if avg[11] then avg[11] = nil end -- keep it at 10?
  	for i,x in ipairs(avg) do
		sum=sum+x
	end
	print("Average for the last " .. #avg .. " frames: " .. sum/#avg)
end

Off-topic question; what type of script is this?

Animation Module that moves an engine around:

https://i.gyazo.com/71abef5564289cd19b1c48e9a69a8f86.mp4

Oh okay, needed to know lol. (000000)

  1. Do you really need to optimise this? It seems like the code you’ve written is going to work super fast if you’re just inserting stuff into a table
    The bit which might cause lag is print, thats an expensive call, but again it should be fine

  2. Use the microprofiler rather than a rolling average thing like this