On Wed, May 29, 2013 at 9:26 PM, Tim Starling <tstarling(a)wikimedia.org>wrote;wrote:
37% for the larger replacement array in
Html::expandAttributes(), or
for the smaller one in Html::element()? And what was the test case
size: how many replaced bytes compared to non-replaced bytes?
If it was the strtr() in Html::element(), which is the only one which
gives a size reduction, perhaps you should compare it against
htmlspecialchars($s, ENT_NOQUOTES), which should use the same
algorithm as plain htmlspecialchars() but with the same size reduction
as strtr().
Ran another test. I tested on the string
'<&<&<&herllowodsiojgd<&sd<^<6&&"""'
repeated 50 times, and I ran the
replacement function 500,000 times. The results were:
htmlspecialchars with ENT_NOQUOTES: 14.025s
htmlspecialchars without ENT_NOQUOTES: 13.457s
strtr: 24.842s
str_replace: 13.184s
Of course, these numbers tend to vary +/- 0.25s every time, so take it with
a grain of salt.
*-- *
*Tyler Romeo*
Stevens Institute of Technology, Class of 2016
Major in Computer Science
www.whizkidztech.com | tylerromeo(a)gmail.com