Note: Sorry that I edited your post; I cleaned up your code a little for readability.
I have no idea how large your items are, but I can imagine that timing something passing a sensor can be quite a challenge and may need to be very accurate (depending on size and speed).
Having said that;
The Arduino may not be very suitable for this, since timing would require a proper "interrupt" to catch a precise value.
Meaning: your code is still running (the loop), but will not get interrupted when the item passes the sensor (start and stop).
What you could do, ... use an ESP32 microcontroller instead of an Arduino (you're not posting what kind of device you're using).
Here my short article on how to use an ESP8266 instead of an Arduino (works the same for ESP32).
It's easy to use and can be used like an Arduino - and those controllers are cheaper, have more memory, have WiFi, and are faster than most Arduino's.
The cool part of these ESP32 controllers is that they are multi core!
Normally you'd use only one of them, but you can actually use both.
To use that second core, you'll have to tinker a little, but it's not hard at all: See this article: "How to use ESP32 Dual Core with Arduino IDE".
So the idea being that the 2nd core does the more precise timing for items passing, and handing over the result to the main core.
(Eg. Core 1 = your main program, Core 2 = constantly measuring)
Another option would be using a microswitch and a very light "arm" that is gently pressing the microswitch while the object is passing.
Since it is an actual switch, you could tie this on the Arduino to an interrupt, which allows you to do a precise timing.
In that case you'd start with the switch = off, time_start = 0.
Once the switch is touched, time_start=now (switch=on).
Keep doing a while loop until switch=off again, and the duration = now - time_start.
Again; I'm just doing some initial guesses right now, since I do not have a good idea of what we're working with (microcontroller, package sizes, speed etc).