Mantis Bugtracker
  

Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0002198 [Quercus] minor always 11-21-07 19:14 11-27-07 13:51
Reporter koreth View Status public  
Assigned To nam
Priority normal Resolution fixed Platform
Status closed   OS
Projection none   OS Version
ETA none Fixed in Version 3.1.4 Product Version 3.1.4
  Product Build
Summary 0002198: strtr() is very slow with an array of replacements
Description If you pass more than one replacement string in an array, strtr() becomes horribly slow.

<?php
header('Content-type: text/plain');
$str = str_repeat("x\n", 10000);

$start_time = microtime(true);
$x = strtr($str, "\n", '\\n');
$end_time = microtime(true);
print "simple strtr = " . ($end_time - $start_time) . "\n";

$start_time = microtime(true);
$x = strtr($str, array("\n"=>'\\n'));
$end_time = microtime(true);
print "1-element array strtr = " . ($end_time - $start_time) . "\n";

$start_time = microtime(true);
$x = strtr($str, array("\n"=>'\\n', "\r"=>'\\r'));
$end_time = microtime(true);
print "2-element array strtr = " . ($end_time - $start_time) . "\n";

$start_time = microtime(true);
$x = strtr($str, array("\n"=>'\\n', "\r"=>'\\r', "&"=>'&amp;'));
$end_time = microtime(true);
print "3-element array strtr = " . ($end_time - $start_time) . "\n";

$start_time = microtime(true);
$x = strtr($str, array("\n"=>'\\n', "\r"=>'\\r', "&"=>'&amp;', "a"=>"b"));
$end_time = microtime(true);
print "4-element array strtr = " . ($end_time - $start_time) . "\n";


Vanilla PHP output:

simple strtr = 0.00012397766113281
1-element array strtr = 0.0010809898376465
2-element array strtr = 0.0010781288146973
3-element array strtr = 0.0010428428649902
4-element array strtr = 0.0010390281677246

Quercus output:

simple strtr = 4.2999908328056335E-4
1-element array strtr = 0.0019129998981952667
2-element array strtr = 0.3932980000972748
3-element array strtr = 0.6140780001878738
4-element array strtr = 0.9110129997134209
Steps To Reproduce
Additional Information
Attached Files

- Relationships

- Notes
(0002522)
nam
11-27-07 13:51

php/112t

performance improved by about 20 times
 

- Issue History
Date Modified Username Field Change
11-21-07 19:14 koreth New Issue
11-26-07 14:34 nam Status new => assigned
11-26-07 14:34 nam Assigned To  => nam
11-27-07 13:51 nam Status assigned => closed
11-27-07 13:51 nam Note Added: 0002522
11-27-07 13:51 nam Resolution open => fixed
11-27-07 13:51 nam Fixed in Version  => 3.1.4


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
29 total queries executed.
26 unique queries executed.
Powered by Mantis Bugtracker