Skip to main content
order by speed
Source Link

Since you seem to be interested in performance, I profiled these with firebug. Here are the results I got:

str.replace( /  +/g, ' ' )  -> 790ms380ms str.replace( / +\s\s+/g, ' ' )  -> 380ms390ms str.replace( / {2,}/g, ' ' ) -> 470ms str.replace( /\s\s+ +/g, ' ' )  -> 390ms790ms str.replace( / +(?= )/g, ' ') -> 3250ms 

This is on Firefox, running 100k string replacements.

I encourage you to do your own profiling tests with firebug, if you think performance is an issue. Humans are notoriously bad at predicting where the bottlenecks in their programs lie.

(Also, note that IE 8's developer toolbar also has a profiler built in -- it might be worth checking what the performance is like in IE.)

Since you seem to be interested in performance, I profiled these with firebug. Here are the results I got:

str.replace( / +/g, ' ' )  -> 790ms str.replace( / +/g, ' ' )  -> 380ms str.replace( / {2,}/g, ' ' ) -> 470ms str.replace( /\s\s+/g, ' ' ) -> 390ms str.replace( / +(?= )/g, ' ') -> 3250ms 

This is on Firefox, running 100k string replacements.

I encourage you to do your own profiling tests with firebug, if you think performance is an issue. Humans are notoriously bad at predicting where the bottlenecks in their programs lie.

(Also, note that IE 8's developer toolbar also has a profiler built in -- it might be worth checking what the performance is like in IE.)

Since you seem to be interested in performance, I profiled these with firebug. Here are the results I got:

str.replace( /  +/g, ' ' ) -> 380ms str.replace( /\s\s+/g, ' ' ) -> 390ms str.replace( / {2,}/g, ' ' ) -> 470ms str.replace( / +/g, ' ' )  -> 790ms str.replace( / +(?= )/g, ' ') -> 3250ms 

This is on Firefox, running 100k string replacements.

I encourage you to do your own profiling tests with firebug, if you think performance is an issue. Humans are notoriously bad at predicting where the bottlenecks in their programs lie.

(Also, note that IE 8's developer toolbar also has a profiler built in -- it might be worth checking what the performance is like in IE.)

added 60 characters in body; edited body; added 1 characters in body
Source Link
Edward Loper
  • 16k
  • 7
  • 48
  • 52

Since you seem to be interested in performance, I profiled these with firebug. Here are the results I got:

str.replace( / +/g, ' ' )  -> 795ms 790ms str.replace( / +/g, ' ' )  -> 379ms 380ms str.replace( / {2,}/g, ' ' )  -> 467ms 470ms str.replace( /\s\s+/g, ' ' )  -> 391ms 390ms str.replace( / +(?= )/g, ' ') -> 3250ms 

This is on Firefox, running 100k string replacements.

I encourage you to do your own profiling tests with firebug, if you think performance is an issue. Humans are notoriously bad at predicting where the bottlenecks in their programs lie.

(Also, note that IE 8's developer toolbar also has a profiler built in -- it might be worth checking what the performance is like in IE.)

Since you seem to be interested in performance, I profiled these with firebug. Here are the results I got:

str.replace( / +/g, ' ' ) -> 795ms str.replace( / +/g, ' ' ) -> 379ms str.replace( / {2,}/g, ' ' ) -> 467ms str.replace( /\s\s+/g, ' ' ) -> 391ms 

This is on Firefox, running 100k string replacements.

I encourage you to do your own profiling tests with firebug, if you think performance is an issue. Humans are notoriously bad at predicting where the bottlenecks in their programs lie.

(Also, note that IE 8's developer toolbar also has a profiler built in -- it might be worth checking what the performance is like in IE.)

Since you seem to be interested in performance, I profiled these with firebug. Here are the results I got:

str.replace( / +/g, ' ' )  ->  790ms str.replace( / +/g, ' ' )  ->  380ms str.replace( / {2,}/g, ' ' )  ->  470ms str.replace( /\s\s+/g, ' ' )  ->  390ms str.replace( / +(?= )/g, ' ') -> 3250ms 

This is on Firefox, running 100k string replacements.

I encourage you to do your own profiling tests with firebug, if you think performance is an issue. Humans are notoriously bad at predicting where the bottlenecks in their programs lie.

(Also, note that IE 8's developer toolbar also has a profiler built in -- it might be worth checking what the performance is like in IE.)

Source Link
Edward Loper
  • 16k
  • 7
  • 48
  • 52

Since you seem to be interested in performance, I profiled these with firebug. Here are the results I got:

str.replace( / +/g, ' ' ) -> 795ms str.replace( / +/g, ' ' ) -> 379ms str.replace( / {2,}/g, ' ' ) -> 467ms str.replace( /\s\s+/g, ' ' ) -> 391ms 

This is on Firefox, running 100k string replacements.

I encourage you to do your own profiling tests with firebug, if you think performance is an issue. Humans are notoriously bad at predicting where the bottlenecks in their programs lie.

(Also, note that IE 8's developer toolbar also has a profiler built in -- it might be worth checking what the performance is like in IE.)