/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] urlencode() speed

Does anyone have information an the speed of urlencode() with large strings?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@pcthugSep 19.2006 — Seems pretty efficient to me. Here is my benchmark code;
[code=php]
<pre><?php

$string = "32 &#32; |143 &#65533; &#143;
33 ! &#33; |144 &#65533; &#144;
34 " &#34; |145 ‘ &#145;
35 # &#35; |146 ’ &#146;
36 $ &#36; |147 “ &#147;
37 % &#37; |148 ” &#148;
38 & &#38; |149 • &#149;
39 ' &#39; |150 – &#150;
40 ( &#40; |151 — &#151;
41 ) &#41; |152 ˜ &#152;
42 * &#42; |153 ™ &#153;
43 + &#43; |154 š &#154;
44 , &#44; |155 › &#155;
45 - &#45; |156 œ &#156;
46 . &#46; |157 &#65533; &#157;
47 / &#47; |158 ž &#158;
48 0 &#48; |159 Ÿ &#159;
49 1 &#49; |160 &#160;
50 2 &#50; |161 ¡ &#161;
51 3 &#51; |162 ¢ &#162;
52 4 &#52; |163 £ &#163;
53 5 &#53; |164 ¤ &#164;
54 6 &#54; |165 ¥ &#165;
55 7 &#55; |166 ¦ &#166;
56 8 &#56; |167 § &#167;
57 9 &#57; |168 ¨ &#168;
58 : &#58; |169 © &#169;
59 ; &#59; |170 ª &#170;
60 < &#60; |171 « &#171;
61 = &#61; |172 ¬ &#172;
62 > &#62; |173 * &#173;
63 ? &#63; |174 ® &#174;
64 @ &#64; |175 ¯ &#175;
65 A &#65; |176 ° &#176;
66 B &#66; |177 ± &#177;
67 C &#67; |178 ² &#178;
68 D &#68; |179 ³ &#179;
69 E &#69; |180 ´ &#180;
70 F &#70; |181 µ &#181;
71 G &#71; |182 ¶ &#182;
72 H &#72; |183 · &#183;
73 I &#73; |184 ¸ &#184;
74 J &#74; |185 ¹ &#185;
75 K &#75; |186 º &#186;
76 L &#76; |187 » &#187;
77 M &#77; |188 ¼ &#188;
78 N &#78; |189 ½ &#189;
79 O &#79; |190 ¾ &#190;
80 P &#80; |191 ¿ &#191;
81 Q &#81; |192 À &#192;
82 R &#82; |193 Á &#193;
83 S &#83; |194 Â &#194;
84 T &#84; |195 Ã &#195;
85 U &#85; |196 Ä &#196;
86 V &#86; |197 Å &#197;
87 W &#87; |198 Æ &#198;
88 X &#88; |199 Ç &#199;
89 Y &#89; |200 È &#200;
90 Z &#90; |201 É &#201;
91 [ &#91; |202 Ê &#202;
92 &#92; |203 Ë &#203;
93 ] &#93; |204 Ì &#204;
94 ^ &#94; |205 Í &#205;
95 _ &#95; |206 Î &#206;
96 &amp;#96; |207 Ï &amp;#207;
97 a &amp;#97; |208 Ð &amp;#208;
98 b &amp;#98; |209 Ñ &amp;#209;
99 c &amp;#99; |210 Ò &amp;#210;
100 d &amp;#100; |211 Ó &amp;#211;
101 e &amp;#101; |212 Ô &amp;#212;
102 f &amp;#102; |213 Õ &amp;#213;
103 g &amp;#103; |214 Ö &amp;#214;
104 h &amp;#104; |215 × &amp;#215;
105 i &amp;#105; |216 Ø &amp;#216;
106 j &amp;#106; |217 Ù &amp;#217;
107 k &amp;#107; |218 Ú &amp;#218;
108 l &amp;#108; |219 Û &amp;#219;
109 m &amp;#109; |220 Ü &amp;#220;
110 n &amp;#110; |221 Ý &amp;#221;
111 o &amp;#111; |222 Þ &amp;#222;
112 p &amp;#112; |223 ß &amp;#223;
113 q &amp;#113; |224 à &amp;#224;
114 r &amp;#114; |225 á &amp;#225;
115 s &amp;#115; |226 â &amp;#226;
116 t &amp;#116; |227 ã &amp;#227;
117 u &amp;#117; |228 ä &amp;#228;
118 v &amp;#118; |229 å &amp;#229;
119 w &amp;#119; |230 æ &amp;#230;
120 x &amp;#120; |231 ç &amp;#231;
121 y &amp;#121; |232 è &amp;#232;
122 z &amp;#122; |233 é &amp;#233;
123 { &amp;#123; |234 ê &amp;#234;
124 | &amp;#124; |235 ë &amp;#235;
125 } &amp;#125; |236 ì &amp;#236;
126 ~ &amp;#126; |237 í &amp;#237;
127  &amp;#127; |238 î &amp;#238;
128 € &amp;#128; |239 ï &amp;#239;
129 &amp;#65533; &amp;#129; |240 ð &amp;#240;
130 ‚ &amp;#130; |241 ñ &amp;#241;
131 ƒ &amp;#131; |242 ò &amp;#242;
132 „ &amp;#132; |243 ó &amp;#243;
133 … &amp;#133; |244 ô &amp;#244;
134 † &amp;#134; |245 õ &amp;#245;
135 ‡ &amp;#135; |246 ö &amp;#246;
136 ˆ &amp;#136; |247 ÷ &amp;#247;
137 ‰ &amp;#137; |248 ø &amp;#248;
138 Š &amp;#138; |249 ù &amp;#249;
139 ‹ &amp;#139; |250 ú &amp;#250;
140 Œ &amp;#140; |251 û &amp;#251;
141 &amp;#65533; &amp;#141; |252 ü &amp;#252;
142 Ž &amp;#142; |253 ý &amp;#253;
143 &amp;#65533; &amp;#143; |254 þ &amp;#254;
32 &amp;#32; |143 &amp;#65533; &amp;#143;
33 ! &amp;#33; |144 &amp;#65533; &amp;#144;
34 " &amp;#34; |145 ‘ &amp;#145;
35 # &amp;#35; |146 ’ &amp;#146;
36 $ &amp;#36; |147 “ &amp;#147;
37 % &amp;#37; |148 ” &amp;#148;
38 &amp; &amp;#38; |149 • &amp;#149;
39 ' &amp;#39; |150 – &amp;#150;
40 ( &amp;#40; |151 — &amp;#151;
41 ) &amp;#41; |152 ˜ &amp;#152;
42 * &amp;#42; |153 ™ &amp;#153;
43 + &amp;#43; |154 š &amp;#154;
44 , &amp;#44; |155 › &amp;#155;
45 - &amp;#45; |156 œ &amp;#156;
46 . &amp;#46; |157 &amp;#65533; &amp;#157;
47 / &amp;#47; |158 ž &amp;#158;
48 0 &amp;#48; |159 Ÿ &amp;#159;
49 1 &amp;#49; |160 &amp;#160;
50 2 &amp;#50; |161 ¡ &amp;#161;
51 3 &amp;#51; |162 ¢ &amp;#162;
52 4 &amp;#52; |163 £ &amp;#163;
53 5 &amp;#53; |164 ¤ &amp;#164;
54 6 &amp;#54; |165 ¥ &amp;#165;
55 7 &amp;#55; |166 ¦ &amp;#166;
56 8 &amp;#56; |167 § &amp;#167;
57 9 &amp;#57; |168 ¨ &amp;#168;
58 : &amp;#58; |169 © &amp;#169;
59 ; &amp;#59; |170 ª &amp;#170;
60 &lt; &amp;#60; |171 « &amp;#171;
61 = &amp;#61; |172 ¬ &amp;#172;
62 &gt; &amp;#62; |173 * &amp;#173;
63 ? &amp;#63; |174 ® &amp;#174;
64 @ &amp;#64; |175 ¯ &amp;#175;
65 A &amp;#65; |176 ° &amp;#176;
66 B &amp;#66; |177 ± &amp;#177;
67 C &amp;#67; |178 ² &amp;#178;
68 D &amp;#68; |179 ³ &amp;#179;
69 E &amp;#69; |180 ´ &amp;#180;
70 F &amp;#70; |181 µ &amp;#181;
71 G &amp;#71; |182 ¶ &amp;#182;
72 H &amp;#72; |183 · &amp;#183;
73 I &amp;#73; |184 ¸ &amp;#184;
74 J &amp;#74; |185 ¹ &amp;#185;
75 K &amp;#75; |186 º &amp;#186;
76 L &amp;#76; |187 » &amp;#187;
77 M &amp;#77; |188 ¼ &amp;#188;
78 N &amp;#78; |189 ½ &amp;#189;
79 O &amp;#79; |190 ¾ &amp;#190;
80 P &amp;#80; |191 ¿ &amp;#191;
81 Q &amp;#81; |192 À &amp;#192;
82 R &amp;#82; |193 Á &amp;#193;
83 S &amp;#83; |194 Â &amp;#194;
84 T &amp;#84; |195 Ã &amp;#195;
85 U &amp;#85; |196 Ä &amp;#196;
86 V &amp;#86; |197 Å &amp;#197;
87 W &amp;#87; |198 Æ &amp;#198;
88 X &amp;#88; |199 Ç &amp;#199;
89 Y &amp;#89; |200 È &amp;#200;
90 Z &amp;#90; |201 É &amp;#201;
91 [ &amp;#91; |202 Ê &amp;#202;
92 &amp;#92; |203 Ë &amp;#203;
93 ] &amp;#93; |204 Ì &amp;#204;
94 ^ &amp;#94; |205 Í &amp;#205;
95 _ &amp;#95; |206 Î &amp;#206;
96
&#96; |207 Ï &#207;
97 a &#97; |208 Ð &#208;
98 b &#98; |209 Ñ &#209;
99 c &#99; |210 Ò &#210;
100 d &#100; |211 Ó &#211;
101 e &#101; |212 Ô &#212;
102 f &#102; |213 Õ &#213;
103 g &#103; |214 Ö &#214;
104 h &#104; |215 × &#215;
105 i &#105; |216 Ø &#216;
106 j &#106; |217 Ù &#217;
107 k &#107; |218 Ú &#218;
108 l &#108; |219 Û &#219;
109 m &#109; |220 Ü &#220;
110 n &#110; |221 Ý &#221;
111 o &#111; |222 Þ &#222;
112 p &#112; |223 ß &#223;
113 q &#113; |224 à &#224;
114 r &#114; |225 á &#225;
115 s &#115; |226 â &#226;
116 t &#116; |227 ã &#227;
117 u &#117; |228 ä &#228;
118 v &#118; |229 å &#229;
119 w &#119; |230 æ &#230;
120 x &#120; |231 ç &#231;
121 y &#121; |232 è &#232;
122 z &#122; |233 é &#233;
123 { &#123; |234 ê &#234;
124 | &#124; |235 ë &#235;
125 } &#125; |236 ì &#236;
126 ~ &#126; |237 í &#237;
127  &#127; |238 î &#238;
128 € &#128; |239 ï &#239;
129 &#65533; &#129; |240 ð &#240;
130 ‚ &#130; |241 ñ &#241;
131 ƒ &#131; |242 ò &#242;
132 „ &#132; |243 ó &#243;
133 … &#133; |244 ô &#244;
134 † &#134; |245 õ &#245;
135 ‡ &#135; |246 ö &#246;
136 ˆ &#136; |247 ÷ &#247;
137 ‰ &#137; |248 ø &#248;
138 Š &#138; |249 ù &#249;
139 ‹ &#139; |250 ú &#250;
140 Œ &#140; |251 û &#251;
141 &#65533; &#141; |252 ü &#252;
142 Ž &#142; |253 ý &#253;
143 &#65533; &#143; |254 þ &#254;
32 &#32; |143 &#65533; &#143;
33 ! &#33; |144 &#65533; &#144;
34 " &#34; |145 ‘ &#145;
35 # &#35; |146 ’ &#146;
36 $ &#36; |147 “ &#147;
37 % &#37; |148 ” &#148;
38 & &#38; |149 • &#149;
39 ' &#39; |150 – &#150;
40 ( &#40; |151 — &#151;
41 ) &#41; |152 ˜ &#152;
42 * &#42; |153 ™ &#153;
43 + &#43; |154 š &#154;
44 , &#44; |155 › &#155;
45 - &#45; |156 œ &#156;
46 . &#46; |157 &#65533; &#157;
47 / &#47; |158 ž &#158;
48 0 &#48; |159 Ÿ &#159;
49 1 &#49; |160 &#160;
50 2 &#50; |161 ¡ &#161;
51 3 &#51; |162 ¢ &#162;
52 4 &#52; |163 £ &#163;
53 5 &#53; |164 ¤ &#164;
54 6 &#54; |165 ¥ &#165;
55 7 &#55; |166 ¦ &#166;
56 8 &#56; |167 § &#167;
57 9 &#57; |168 ¨ &#168;
58 : &#58; |169 © &#169;
59 ; &#59; |170 ª &#170;
60 < &#60; |171 « &#171;
61 = &#61; |172 ¬ &#172;
62 > &#62; |173 * &#173;
63 ? &#63; |174 ® &#174;
64 @ &#64; |175 ¯ &#175;
65 A &#65; |176 ° &#176;
66 B &#66; |177 ± &#177;
67 C &#67; |178 ² &#178;
68 D &#68; |179 ³ &#179;
69 E &#69; |180 ´ &#180;
70 F &#70; |181 µ &#181;
71 G &#71; |182 ¶ &#182;
72 H &#72; |183 · &#183;
73 I &#73; |184 ¸ &#184;
74 J &#74; |185 ¹ &#185;
75 K &#75; |186 º &#186;
76 L &#76; |187 » &#187;
77 M &#77; |188 ¼ &#188;
78 N &#78; |189 ½ &#189;
79 O &#79; |190 ¾ &#190;
80 P &#80; |191 ¿ &#191;
81 Q &#81; |192 À &#192;
82 R &#82; |193 Á &#193;
83 S &#83; |194 Â &#194;
84 T &#84; |195 Ã &#195;
85 U &#85; |196 Ä &#196;
86 V &#86; |197 Å &#197;
87 W &#87; |198 Æ &#198;
88 X &#88; |199 Ç &#199;
89 Y &#89; |200 È &#200;
90 Z &#90; |201 É &#201;
91 [ &#91; |202 Ê &#202;
92 &#92; |203 Ë &#203;
93 ] &#93; |204 Ì &#204;
94 ^ &#94; |205 Í &#205;
95 _ &#95; |206 Î &#206;
96 ` &#96; |207 Ï &#207;
97 a &#97; |208 Ð &#208;
98 b &#98; |209 Ñ &#209;
99 c &#99; |210 Ò &#210;
100 d &#100; |211 Ó &#211;
101 e &#101; |212 Ô &#212;
102 f &#102; |213 Õ &#213;
103 g &#103; |214 Ö &#214;
104 h &#104; |215 × &#215;
105 i &#105; |216 Ø &#216;
106 j &#106; |217 Ù &#217;
107 k &#107; |218 Ú &#218;
108 l &#108; |219 Û &#219;
109 m &#109; |220 Ü &#220;
110 n &#110; |221 Ý &#221;
111 o &#111; |222 Þ &#222;
112 p &#112; |223 ß &#223;
113 q &#113; |224 à &#224;
114 r &#114; |225 á &#225;
115 s &#115; |226 â &#226;
116 t &#116; |227 ã &#227;
117 u &#117; |228 ä &#228;
118 v &#118; |229 å &#229;
119 w &#119; |230 æ &#230;
120 x &#120; |231 ç &#231;
121 y &#121; |232 è &#232;
122 z &#122; |233 é &#233;
123 { &#123; |234 ê &#234;
124 | &#124; |235 ë &#235;
125 } &#125; |236 ì &#236;
126 ~ &#126; |237 í &#237;
127  &#127; |238 î &#238;
128 € &#128; |239 ï &#239;
129 &#65533; &#129; |240 ð &#240;
130 ‚ &#130; |241 ñ &#241;
131 ƒ &#131; |242 ò &#242;
132 „ &#132; |243 ó &#243;
133 … &#133; |244 ô &#244;
134 † &#134; |245 õ &#245;
135 ‡ &#135; |246 ö &#246;
136 ˆ &#136; |247 ÷ &#247;
137 ‰ &#137; |248 ø &#248;
138 Š &#138; |249 ù &#249;
139 ‹ &#139; |250 ú &#250;
140 Œ &#140; |251 û &#251;
141 &#65533; &#141; |252 ü &#252;
142 Ž &#142; |253 ý &#253;
143 &#65533; &#143; |254 þ &#254;
32 &#32; |143 &#65533; &#143;
33 ! &#33; |144 &#65533; &#144;
34 " &#34; |145 ‘ &#145;
35 # &#35; |146 ’ &#146;
36 $ &#36; |147 “ &#147;
37 % &#37; |148 ” &#148;
38 & &#38; |149 • &#149;
39 ' &#39; |150 – &#150;
40 ( &#40; |151 — &#151;
41 ) &#41; |152 ˜ &#152;
42 * &#42; |153 ™ &#153;
43 + &#43; |154 š &#154;
44 , &#44; |155 › &#155;
45 - &#45; |156 œ &#156;
46 . &#46; |157 &#65533; &#157;
47 / &#47; |158 ž &#158;
48 0 &#48; |159 Ÿ &#159;
49 1 &#49; |160 &#160;
50 2 &#50; |161 ¡ &#161;
51 3 &#51; |162 ¢ &#162;
52 4 &#52; |163 £ &#163;
53 5 &#53; |164 ¤ &#164;
54 6 &#54; |165 ¥ &#165;
55 7 &#55; |166 ¦ &#166;
56 8 &#56; |167 § &#167;
57 9 &#57; |168 ¨ &#168;
58 : &#58; |169 © &#169;
59 ; &#59; |170 ª &#170;
60 < &#60; |171 « &#171;
61 = &#61; |172 ¬ &#172;
62 > &#62; |173 * &#173;
63 ? &#63; |174 ® &#174;
64 @ &#64; |175 ¯ &#175;
65 A &#65; |176 ° &#176;
66 B &#66; |177 ± &#177;
67 C &#67; |178 ² &#178;
68 D &#68; |179 ³ &#179;
69 E &#69; |180 ´ &#180;
70 F &#70; |181 µ &#181;
71 G &#71; |182 ¶ &#182;
72 H &#72; |183 · &#183;
73 I &#73; |184 ¸ &#184;
74 J &#74; |185 ¹ &#185;
75 K &#75; |186 º &#186;
76 L &#76; |187 » &#187;
77 M &#77; |188 ¼ &#188;
78 N &#78; |189 ½ &#189;
79 O &#79; |190 ¾ &#190;
80 P &#80; |191 ¿ &#191;
81 Q &#81; |192 À &#192;
82 R &#82; |193 Á &#193;
83 S &#83; |194 Â &#194;";

function urlencode_benchmark() {
global $string;
$start = microtime(true);
echo urlencode($string);
return (microtime(true) - $start);
}

$seed = microtime(true); // because the first call has a tendency to be slower
$time = array();

for($i=0; $i<25; $i++)
{
$time[$i] = urlencode_benchmark();
}

echo "nnAverage:";
echo sprintf("%01.4f", array_sum($time) / count($time));
?></pre>
[/code]
Copy linkTweet thisAlerts:
@shane_carrauthorSep 20.2006 — Thanks pcthug. urlencode seems to work well, but for urldecode, it's at like .83 seconds or something when I run the text that was produced from this script. Is there a way to remove semicolons from text and put them back again? ex:

[code=php]$a = "test;test;test(semi)test";
$b = str_replace(";", "(semi)", $a);
//works fine, but decoded
$c = str_replace("(semi)", ";", $b);
echo (($a==$c)?"It worked":"See? How can I avoid this problem? This is the only reason that I'm using urlencode and decode for this. What else can I do?");[/code]
Copy linkTweet thisAlerts:
@shane_carrauthorSep 22.2006 — Okay, I got this code, and it seems to work:

[code=php]$char = ";"; //character to remove
$rep = "¤"; //character to replace
$mark = "<orig"; //string to show an already-existent character
$orig = "string to remove character from";
$form = str_replace($rep, $rep.$mark, $orig); //take all of the $rep character and show that it already existed
$form = str_replace($char, $rep, $form); //remove all $char's and replace them with $rep's
//$form is the formatted string, and it has none of $char.

$temp = explode($rep, $form); //find all $reps and split the array
if(!is_array($temp))$temp=array(2); //if there were no $rep's in the formatted string
$new = $temp[0];
array_shift($temp);
foreach($temp as $value){ //evaluate every value in the $temp array
if(substr($value, 0, strlen($mark))==$mark){ //if the character is marked original
$new .= $rep.substr($value, strlen($mark)); //add $rep
}else{
$new .= $char.$value; //otherwise add $char
}
}
//$new is now the un-formatted string, and $orig == $new.[/code]


So I suppose that I'm done now!
×

Success!

Help @shane_carr spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...