You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I received a link to this repo from a colleague as an evidence using (int) (type cast) is faster than using intval(...).
I ran the scripts with only this addition:
$ diff test test-example
64d63
<$application->setRepeats($argv[2] ?? 10000);
So I could run tests with an arbitrary repeat number.
Running the included IntvalVsTypeCast I got these results:
$ ./test IntvalVsTypeCast 1000000
# omitted progress bars for brevity
Test name Repeats Result Performance
(int) 1000000 0.115288 sec +0.00%
intval() 1000000 0.120689 sec -4.68%
Which seems to validate my colleague assumption.
But then I created a new class and just inverted the tests (code at end) and got inverted results:
$ ./test TypeCastVsIntval 1000000
# omitted progress bars for brevity
Test name Repeats Result Performance
intval() 1000000 0.137540 sec +0.00%
(int) 1000000 0.143018 sec -3.98%
Of course the difference is not big enough, and convinced this colleague to stop complaining on me using intval() instead of (int) (also from the progress bar output it seems intval() uses slightly less memory, but it is very unlikely one would need to run a million integer conversion in a row), but I thought it would be a good idea to report.
I didn't run other tests to check if this issue holds true for all of them. And of course, I ran both tests several times before posting this issue, and the results don't vary very much.
I received a link to this repo from a colleague as an evidence using
(int)
(type cast) is faster than usingintval(...)
.I ran the scripts with only this addition:
So I could run tests with an arbitrary repeat number.
Running the included
IntvalVsTypeCast
I got these results:Which seems to validate my colleague assumption.
But then I created a new class and just inverted the tests (code at end) and got inverted results:
Of course the difference is not big enough, and convinced this colleague to stop complaining on me using
intval()
instead of(int)
(also from the progress bar output it seemsintval()
uses slightly less memory, but it is very unlikely one would need to run a million integer conversion in a row), but I thought it would be a good idea to report.I didn't run other tests to check if this issue holds true for all of them. And of course, I ran both tests several times before posting this issue, and the results don't vary very much.
My system reference:
PHP version:
Added class:
Note: I just inverted the tests from
IntvalVsTypeCast
, although in both classes the tests don't match the class name order.If I can provide any other info to help debug it, please let me know.
The text was updated successfully, but these errors were encountered: