Maybe it's a CPU cache thing. I'm just guessing because I expect the code path you're benchmarking to be identical.I would guess it is because both the number AND the string representation are copied:
In summary - the slowdown effect should only be noticable when you're copying the variables: as you implied, using arithmatic on numbers that are also stringified should not slow down (much).perl -MDevel::Peek -e'$x=42; "$x"; $y = $x; Dump $y' SV = PVIV(0x814e9a8) at 0x814d518 REFCNT = 1 FLAGS = (IOK,POK,pIOK,pPOK) IV = 42 PV = 0x8168e70 "42"\0 CUR = 2 LEN = 4
update: Ieronim, the issue is that when you stringify a number, perl stores both representations in the variable.
When you copy it, perl doesn't know whether you're going to use the copies as string or numbers, so it copies the whole variable (since that should be faster than copying only one representation and converting it later).
In reply to Re^2: Don't treat your numbers as strings, or Interpolation is worse than you might think
by Joost
in thread Don't treat your numbers as strings, or Interpolation is worse than you might think
by Ieronim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |