There's been times where I've spent weeks or even months going down a path that has ultimately proven fruitless, including spending really long hours on it. That certainly counts as work, but if it results in no meaningful value being produced, then what's the point?
There's been other times when I've gone on holiday and come back refreshed and incredibly motivated, having realised the solution to a problem that I'd been struggling with because I gave my subconscious mind time to do its thing without interruption. Does spending time at the beach, exploring ancient towns in Italy, or even just taking a shower count as work? Most people would say no, but that's when I've had some of my best ideas.
Sometimes in a meeting I'll be having a discussion with a colleague and we'll come up with a solution for something we've been trying do that requires zero changes to the our codebase, something we refer to as a "no-code" solution. Those can shave off weeks of time. Technically, that meeting counted as two hours of work; is that less productive than spending a ton of time implementing a feature that turned out to be unnecessary because there was a way to avoid the need for it?
As far as when I actually sitting at my desk focusing on work, I value reading and thinking much more than implementation. Coding is the easy part; once the solution is clear, getting it into the computer is fairly straightforward, albeit quite tedious. I've spent lots of time coding the wrong thing, which with a bit more thought and research could have been avoided. I consider that time mostly wasted, except perhaps for the learning experience.
Judge your productivity by what you achieve, not how long it takes you to do it.
Edit: A thought experiment I'd like to add. Imagine you give two people the same task and ask them to complete it in one week. One person works on it four hours a day, the other six. They both get it done on time, at the same level of quality. The first person was actually _more_ productive than the second.