First, please read: PSA: how to quote code with backticks
Then, have you read through Performance Tips · The Julia Language?
It has a lot of good advice, for this code, Performance Tips · The Julia Language should be especially useful.
It’s a bit unclear to me what this means. Putting code inside functions is a good idea, yes. Where the code exists (if it is in e.g. a file or the REPL) doesn’t matter for the performance of it.