in reply to Re^3: What to test in a new module
in thread What to test in a new module

++ My response may come across as negative. That's not my intention so I'm just letting you know that I upvoted your post before replying. :-)

"I hadn't thought of the speed implications."

Unless you're experiencing noticeable speed issues, continue to not think about it. This sort of micro-optimisation is rarely useful: you'll spend inordinate amounts of time possibly saving just some nanoseconds when it would be more productive to focus on the code in general.

"But I guess concatenation is always going to be faster than interpolation."

Don't guess; instead, Benchmark.

I seem to recall 20+ years ago, when coding to v5.6, various forms of concatenation (e.g. join '', $x, $y or $x . $y or "$x$y" or others) provided certain performance benefits. Reading the optimisation sections of release notes over the years has shown that these benefits have largely dissipated.

In the main, I would focus on readability. For instance, many authors eschew whitespace, resulting in code like $x.'.'.$y which I find difficult to read at first glance, and often require me to do a doubletake to determine what each dot is doing.

This advice pertains to many aspects of Perl syntax, not just concatenation, which perhaps had some benefits in the past but have been optimised away as the language has matured.

— Ken

Replies are listed 'Best First'.
Re^5: What to test in a new module
by Bod (Parson) on Jul 09, 2023 at 22:43 UTC
    Unless you're experiencing noticeable speed issues, continue to not think about it (speed)

    Don't guess; instead, Benchmark

    I was guessing because I wasn't dwelling on speed :)

    Unless I have to process lots of something with a big loop, I don't tend to think about speed unless it becomes an issue - my guess was about academic interest rather than practical concern.

    Thanks for the benchmarking link - I have intended to try benchmarking something just so I know how to do it.