When I run this test in 2 threads I expect that running time will be the same, because PostgreSQL will fork process for the second connection and this process will be served by a separate CPU core because I have more than 2 cores.
Yes, IMMUTABLE flag helps, but I think It's just because Postgres actually executes procedure only once.