It’s an example. As another example, using a real life middleware, if you use express-session, using ‘app.use(session({}))’ it sets up a session and then defines req.session to store session data on all your routes. That means you can access this property (‘req.session’) on all routes rather than having it have to be defined each time.
In terms of speed, the example I used will only likely add in the magnitude of 0.01ms to the request. More complex logic will add more time but for raw JS (no db calls, etc), I wouldn’t expect it to add very much extra time to load at all.