Forum Moderators: coopster & phranque

Message Too Old, No Replies

Naming variables in a subroutine faster than using $ [0-9]?

         

csdude55

5:52 pm on Jun 26, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



While playing around with another function, I've made a discovery that seems pretty consistent.

Naming the variables within the subroutine (eg, my ($a, $b) = @_;) is processing 20 times faster than not naming them!

Case in point, these subroutines are identical except for the naming:

[tpcg.io...]

Over 10,000 iterations, named variables processes in 0.018s, while not named variables processes in 0.39s!

I get the same results on jdoodle.com, too.

Thoughts?

csdude55

5:58 pm on Jun 26, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



No, wait, nevermind. I just discovered one difference in the code that I'd overlooked; fixing it made them virtually identical. So I guess that naming them has no impact at all, other than readability. And maybe the time it takes to load the script, since naming them takes more space.

Mea culpa!