In PostgreSQL you typically do this with generate_series:
SELECT my_function()
FROM generate_series(1,5000);
or
SELECT (SELECT my_query ....)
FROM generate_series(1,5000);
In the latter case you can add OFFSET 0 to the subquery or wrap it in a STRICT SQL function to prevent the query planner from pulling out common conditions and subclauses and otherwise being clever.
Timing can be obtained with psql's \timing command, with SET log_duration = on, or with EXPLAIN (ANALYZE, BUFFERS), all of which time subtly different things - see the documentation. In brief, \timing measures time including round-trips and value transfer to the client. log_duration measures server-side execution time. EXPLAIN (ANALYZE, BUFFERS) measures details of the statement's execution but adds timing overhead that can slow it down a bit.